Search code examples
androidkeykeystore

Android store byte[] in the keystore


I'm very confused about the keystore. I found a lot threads about it but nothing works. I want to store and load a specified key (byte[] and not generated) in the keystore. Is that working? I tried a lot but nothing works.

Do you have some codesnippets?

THANKS Jules

Edit:

KeyStore ks = KeyStore.getInstance("AndroidKeyStore");
ks.load(null);
ks.setEntry(alias, entry, param);
OutputStream writeStream = new FileOutputStream(path);
ks.store(writeStream, passwordForKey);
writeStream.close();

Solution

  • You have to use Bas64-Encoding (Android.util.Base64) to store it as a string. There is no function to store a raw byte-Array