简体   繁体   English

如何从keystore.pkcs12文件获取私钥

[英]How to get PrivateKey from keystore.pkcs12 file

I am trying to get privateKey from keystore file, 我正在尝试从密钥库文件中获取privateKey,

    keyStore.load(KeyStoreinputStream, "keystorepass".toCharArray());

PrivateKey key = (PrivateKey) keyStore.getKey(alias, new char[0]);

new char[0] --> I have not given password for private key at the time of generation. new char [0]->在生成时,我还没有提供私钥的密码。

getting below exception: 低于异常:

java.security.UnrecoverableKeyException: Get Key failed: Given final block not properly padded
    at java.security.KeyStore.getKey(KeyStore.java:792)
Caused by: javax.crypto.BadPaddingException: Given final block not properly padded
    at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:811)
    at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:676)
    at com.sun.crypto.provider.PKCS12PBECipherCore.implDoFinal(PKCS12PBECipherCore.java:355)

new char[0] isn't correct. new char[0]不正确。 If there is no key password, use null. 如果没有密钥密码,请使用null.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM