qq_25914767 2016-11-08 10:00 采纳率: 50%
浏览 9968
已采纳

android安全存储,使用AndroidKeyStore的问题

最近在研究android的keystore安全存储,网上就一篇关于这个的博客,但是有些地方没讲清楚,资料非常少。。。

我使用以下方式存储了私钥和证书:

mKeyStore = KeyStore.getInstance("AndroidKeyStore");//获取密钥库

KeyStore.PrivateKeyEntry expected = new KeyStore.PrivateKeyEntry(priKey, expectedChain);

mKeyStore.setEntry("mytestRSAkey", expected, new KeyStoreParameter.Builder(this.getBaseContext()).setEncryptionRequired(true).build());//加密存储

现在我要提取公钥和私钥:

actualEntry = mKeyStore.getEntry("mytestRSAkey",null);//获取密钥

KeyStore.PrivateKeyEntry actual = (KeyStore.PrivateKeyEntry) actualEntry;

pubKey=actual.getCertificate().getPublicKey();

priKey=actual.getPrivateKey();

可能是出于保护私钥的目的,priKey.getEncoded()是获取不到私钥的,只有一个密钥索引,导致我使用使用该私钥解密时出错

public static byte[] decrypt_RSA(byte[] encryptedData, PrivateKey privateKey)

{

try
{

Cipher cipher = Cipher.getInstance("RSA");

cipher.init(Cipher.DECRYPT_MODE, privateKey);

return cipher.doFinal(encryptedData);

} catch (Exception e)

{

return null;

}

}

现在我该怎么使用priKey来解密数据啊

  • 写回答

6条回答

  • qq_25914767 2016-11-09 07:59
    关注

    问题解决,Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");就可以了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料