Pie*_*aux 1 encryption android cryptography aes keystore
首先,我是Android编程的新手,虽然我不是编程本身的新手.实际上,我的目的是将加密密钥保存到Android密钥库中.GOOGLE本身似乎非常缺乏此类信息.由于关于该主题的方法不多,我假设它不是相当标准的知识.那么有人可以给我一个示例代码
所以本质上是密钥库的所有基本功能的代码.提前感谢您的协助.
如果将minSdkVersion设置为23或更高,Android M可以在本月轻松生成和管理对称密钥.
看看这里列出的第四个例子. https://developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.html
 KeyGenerator keyGenerator = KeyGenerator.getInstance(
         KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
 keyGenerator.initialize(
         new KeyGenParameterSpec.Builder("key2",
                 KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
                 .setBlockModes(KeyProperties.BLOCK_MODE_GCM)
                 .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
                 .build());
 SecretKey key = keyGenerator.generateKey();
 Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
 cipher.init(Cipher.ENCRYPT_MODE, key);
 ...
 // The key can also be obtained from the Android Keystore any time as follows:
 KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
 keyStore.load(null);
 key = (SecretKey) keyStore.getKey("key2", null);
| 归档时间: | 
 | 
| 查看次数: | 5162 次 | 
| 最近记录: |