小编Arc*_*rma的帖子

来自keystore的secretkey的编码文本在android M中为null

我需要实现256位AES加密,我参考了这个 - http://nelenkov.blogspot.jp/2015/06/keystore-redesign-in-android-m.html KeyGenerator看起来像这样.

KeyGenerator keyGenerator = KeyGenerator
                    .getInstance(KeyProperties.KEY_ALGORITHM_AES,"AndroidKeyStore");
            KeyGenParameterSpec spec = new KeyGenParameterSpec.Builder(keyName,
                     KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)  

                     .setUserAuthenticationValidityDurationSeconds(5 *11160)
                     .build();
            keyGenerator.init(spec);
            SecretKey key1 =   keyGenerator.generateKey();
Run Code Online (Sandbox Code Playgroud)

当我从keystore导入密钥的编码值时,它返回null给我.

KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
               keyStore.load(null); 
SecretKey key3 = (SecretKey) keyStore.getKey(keyName, null);
Log.d("Test MM",key3.getEncoded()+",");
Run Code Online (Sandbox Code Playgroud)

我在logcat中找到了key3.getEncoded()的null值.请给我一些建议.

android android-keystore android-6.0-marshmallow

3
推荐指数
1
解决办法
1200
查看次数