· 6 years ago · Aug 01, 2019, 07:22 AM
1try {
2 mKeyStore = KeyStore.getInstance("AndroidKeyStore");
3 } catch (KeyStoreException e) {
4 throw new RuntimeException("Failed to get an instance of KeyStore", e);
5 }
6 try {
7 mKeyGenerator = KeyGenerator
8 .getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
9 } catch (NoSuchAlgorithmException | NoSuchProviderException e) {
10 throw new RuntimeException("Failed to get an instance of KeyGenerator", e);
11 }
12
13mKeyStore.load(null);
14SecretKey key = (SecretKey) mKeyStore.getKey(keyName, null);
15
16try {
17 mKeyGenerator = KeyGenerator
18 .getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore")
19 } catch (e: NoSuchAlgorithmException) {
20 throw RuntimeException("Failed to get an instance of KeyGenerator", e)
21 } catch (e: NoSuchProviderException) {
22 throw RuntimeException("Failed to get an instance of KeyGenerator", e)
23 }
24
25mKeyStore?.load(null)
26val key = mKeyStore?.getKey(keyName, null) as? SecretKey