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条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?