在我的应用程序中,我在共享首选项中保存了一些数据,这些数据在保存之前必须加密,并且在检索时必须解密。
我正在使用 AES-256 加密。为此,我正在使用密码/密码生成密钥。下面是我的代码片段。
public static SecretKey generateKey(char[] passphraseOrPin, byte[] salt) throws NoSuchAlgorithmException, InvalidKeySpecException {
// Number of PBKDF2 hardening rounds to use. Larger values increase
// computation time. You should select a value that causes computation
// to take >100ms.
final int iterations = 1000;
// Generate a 256-bit key
final int outputKeyLength = 256;
SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
KeySpec keySpec = new PBEKeySpec(passphraseOrPin, salt, iterations, outputKeyLength);
SecretKey secretKey = secretKeyFactory.generateSecret(keySpec);
return secretKey;
}
根据我的应用程序,我可以要求用户提供一个独特的 pin。但我无法将密码保存在密钥库中,因为该应用程序必须从 4.0.0 开始支持。如何保存图钉?