Skip to content Skip to sidebar Skip to footer

Android Keystore Get Raw Bytes/string Of Stored Key

I can generate a key to be stored in the Android Keystore like so: private static final String AndroidKeyStore = 'AndroidKeyStore'; private static final String AES_MODE = 'AES/GCM/

Solution 1:

The "AndroidKeyStore" is specifically designed to make this impossible or at least very difficult. There is a more complete discussion here, but in summary:

Android Keystore system protects key material from unauthorized use. Firstly, Android Keystore mitigates unauthorized use of key material outside of the Android device by preventing extraction of the key material from application processes and from the Android device as a whole.

Continuing along the lines of your example, the following additional lines of code:

Keykey = keyStore.getKey(KEY_ALIAS, null);
String algorithm = key.getAlgorithm();
String format = key.getFormat();
byte[] encoded = key.getEncoded();

should cause key to be a valid non-null reference to Key object, algorithm should return "AES", but format should be null as should encoded.

Solution 2:

The Key object returned has methods:

getAlgorithm()
getEncoded()
getFormat()

They return String, byte[], and String, respectively.

Click here for more info.

Post a Comment for "Android Keystore Get Raw Bytes/string Of Stored Key"