Android store byte[] in the keystore

2019-06-09 16:05发布

问题:

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();

回答1:

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