Android 4.4 KitKat和Secret Key Factory

随着Android 4.4的发布,开发者需要改变之前通过SecretKeyFactory从Unicode密码断语中生成对称密钥的方法。如果用户允许使用Unicode密码断语,那么这个改变将影响那些使用PBKDF2WithHmacSHA1密钥生成算法的程序。

以前的PBKDF2WithHmacSHA1算法只是关注密码断语中每个字符的低8位。这和由RSA实验室2000年9月发布的PKCS #5: 基于口令的密码系统规范版本2.0相冲突。

由于这是重大的更改,开发者通过使用旧的算法实现向后兼容。这个旧版本已更名为PBKDF2WithHmacSHA1And8bit,并且可以从Android开发者博客中获得其样例代码。

SecretKeyFactory factory;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// Use compatibility key factory -- only uses lower 8-bits of passphrase chars
factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1And8bit");
} else {
// Traditional key factory. Will use lower 8-bits of passphrase chars on
// older Android versions (API level 18 and lower) and all available bits
// on KitKat and newer (API level 19 and higher).
factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
}

查看英文原文:Android 4.4 KitKat and the Secret Key Factory

感谢张龙对本文的审校。

给InfoQ中文站投稿或者参与内容翻译工作,请邮件至[email protected]。也欢迎大家通过新浪微博(@InfoQ)或者腾讯微博(@InfoQ)关注我们,并与我们的编辑和其他读者朋友交流。

你可能感兴趣的:(Android 4.4 KitKat和Secret Key Factory)