【问题标题】:Saving Signed X509Certificate and PrivateKey in Android在 Android 中保存签名的 X509Certificate 和 PrivateKey
【发布时间】:2019-07-13 21:28:52
【问题描述】:

我想将 X509Certificate 及其私钥保存到 Android KeyStore 中,我认为我应该“合并” X509Certificate(包含公钥)及其私钥。私钥用于创建 CSR,然后服务器方签署证书并返回应用程序,我可以将证书和私钥合并为一个唯一的证书吗?我也在使用 spongycastle(又名 bouncycastle 的 android 包装器)。

【问题讨论】:

    标签: java android bouncycastle x509certificate


    【解决方案1】:

    我不知道 Android KeyStore,但也许您可以尝试以下方法:

    PrivateKey privateKey = ...         //this is what you already have
    X509Certificate certificate = ...   //this is what you already have
    
    KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
    keyStore.load(null);
    
    Certificate[] certChain = new Certificate[1];  
    certChain[0] = certificate;  
    
    char[] myKeyPassword = "myKeyPassword".toCharArray();
    keyStore.setKeyEntry("mykeyalias", (Key)privateKey, myKeyPassword, certChain);  
    

    有关 KeyStore.setKeyEntry 的更多信息,请参阅https://docs.oracle.com/javase/9/docs/api/java/security/KeyStore.html#setKeyEntry-java.lang.String-java.security.Key-char:A-java.security.cert.Certificate:A-

    【讨论】:

      猜你喜欢
      • 2023-03-04
      • 2013-12-06
      • 2014-03-07
      • 2019-01-19
      • 1970-01-01
      • 2013-12-15
      • 1970-01-01
      • 2012-11-13
      • 2020-12-16
      相关资源
      最近更新 更多