在未知的PRF算法hmacWithSHA256上用BouncyCastle加载pkcs12文件失败

问题描述

我们有一个由第三方(不是由我们管理)提供的 pkcs#12 格式的证书。在从我们的平台将电子邮件发送给该特定客户之前,我们必须使用此证书对电子邮件进行签名。

旧证书没有问题,但是随着即将过期,我们需要用更新的证书替换它,该证书具有以下密钥加密方案(通过openssl提取):

PBES2,PBKDF2,AES-256-CBC,Iteration 2000,PRF hmacWithSHA256

当尝试使用bouncycastle安全提供程序加载此密钥库时,我们收到以下错误

Caused by: java.io.IOException: exception unwrapping private key - java.security.spec.InvalidKeySpecException: Invalid KeySpec: unknown PRF algorithm 1.2.840.113549.2.9
    at org.bouncycastle.jcajce.provider.keystore.pkcs12.PKCS12KeyStoreSpi.unwrapKey(Unknown Source)
    at org.bouncycastle.jcajce.provider.keystore.pkcs12.PKCS12KeyStoreSpi.engineLoad(Unknown Source)
    at java.security.KeyStore.load(KeyStore.java:1445)
    at org.obfuscated.SignEmailGenerator.loadKeyStore(SignEmailGenerator.java:130)

代码(为简便起见,删除了异常处理和其他实用程序代码):

KeyStore keystore = KeyStore.getInstance("PKCS12",BouncyCastleProvider.PROVIDER_NAME);        
InputStream trustStoreInputStream = MethodHandles.lookup().lookupClass()
                .getResourceAsStream(mailSigningConfiguration.getKeyStorePath());
keystore.load(trustStoreInputStream,mailSigningConfiguration.getKeyStorePassword().toCharArray());

1.2.840.113549.2.9 是hmacWithSHA256的OID,这使我想到了这个问题。充气城堡不支持该算法吗?基于http://www.bouncycastle.org/specifications.html,我猜应该吗?如果它支持它,为什么我无法加载该文件?

Jdk 1.8.0 bcmail-jdk15on版本1.66

感谢您的任何投入,谢谢。

编辑(私钥是文件的一部分):

c:\Programy\OpenSSL-Win64\bin>openssl pkcs12 -info -in PrivateKey.pfx -nodes -nocerts
Enter Import Password:
MAC: sha256,Iteration 2000
MAC length: 32,salt length: 20
PKCS7 Data
Shrouded Keybag: PBES2,PBKDF2,AES-256-CBC,Iteration 2000,PRF hmacWithSHA256
Bag Attributes
    localKeyID: 01 00 00 00
    friendlyName: ---ommited---
    Microsoft CSP Name: Microsoft Enhanced Cryptographic Provider v1.0
Key Attributes
    X509v3 Key Usage: 10
-----BEGIN PRIVATE KEY-----
-- data is here,but I've ommited it ---
-----END PRIVATE KEY-----
PKCS7 Encrypted data: PBES2,PRF hmacWithSHA256
Certificate bag
Certificate bag
Certificate bag

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...