Android安全 - 使用pin存储敏感信息的加密技术

时间:2016-04-06 06:23:23

标签: android security android-security

在我的应用中,我保存了一些共享首选项中的数据,这些数据必须在保存之前加密,并且在检索时必须进行解密。

我正在使用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;
}

根据我的应用,我可以要求用户提供一个独特的引脚。但是我无法在密钥库中保存引脚,因为应用程序必须支持4.0。如何保存引脚?

2 个答案:

答案 0 :(得分:1)

为此,我建议你研究使用Facebook Conceal库。它根据build.gradlehttps://github.com/facebook/conceal/blob/master/build.gradle

与Android 9兼容

您可以在网站上关注如何整合的指导:

https://github.com/facebook/conceal

答案 1 :(得分:1)

请改用KeyChain。它与API 14(ICS)兼容。主要区别在于KeyChain在系统范围内可用。

然而,我想知道,你为什么要存放针?存在受密码保护的密钥以防止未经授权的使用,因此用户应通过输入密码来授权使用。

相关问题