如何安全存储PBEKeySpec密码?

时间:2018-02-09 12:44:43

标签: android encryption cryptography keystore

我有以下方法来导出加密密钥:

private static SecretKey deriveKeySecurely(byte[] salt){
    String password = "FAKE_PASSWORD";
    KeySpec keySpec = new PBEKeySpec(password.toCharArray(), salt, sITERATION_COUNT, sKEY_SIZE_IN_BYTES * 8);
    SecretKeyFactory keyFactory;
    try {
        keyFactory = SecretKeyFactory.getInstance(sALGORITHM);
        byte[] keyBytes = keyFactory.generateSecret(keySpec).getEncoded();
        return new SecretKeySpec(keyBytes, sSECRET_KEY_ALGORTHM);
    } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
        if(BuildConfig.DEBUG){
            Log.e(sLOG_TAG, e.toString());
        }
        return null;
    }
}

在此示例中,密码字符串是硬编码的。我知道我可以使用SharedPreferences来存储这个密码,但我不确定它是否可以安全地使用它。可能是Android KeyStore在某种程度上有用吗?

0 个答案:

没有答案
相关问题