Android : Getting a keystore not initialized error

on Sunday, August 31, 2014


This my code used for usage of key store to save an arbitrary text as a key in the keystore how I am getting the "Keystore is not initialized error", how can I fix this?



public void secretKeyGeneration(View view) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {

KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
byte[] sek = "eru9tyighw34ilty348934i34uiq34q34ri".getBytes();
SecretKey sk = new SecretKeySpec(sek, 0, sek.length, "AES");
char[] password = "keystorepassword".toCharArray();
KeyStore.ProtectionParameter protParam =
new KeyStore.PasswordProtection(password);

KeyStore.SecretKeyEntry skEntry = new KeyStore.SecretKeyEntry(sk);
ks.setEntry("secretKeyAlias", skEntry, protParam);

}

0 comments:

Post a Comment