· 7 years ago · Jun 26, 2018, 03:46 PM
1KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
2keyStore.load(null);
3
4keyGenerator.init(new KeyGenParameterSpec.Builder(alias,
5KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
6 .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
7 .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
8 .build());
9
10keyGenerator.generateKey();
11
12final Cipher cipher = Cipher.getInstance(mTransformation);
13cipher.init(Cipher.ENCRYPT_MODE, secretKey);
14mIV = cipher.getIV();
15byte[] bytes = cipher.doFinal(data.getBytes("UTF-8"));
16return Base64.encodeToString(bytes, Base64.DEFAULT);