gpt4 book ai didi

java - SignerID 转换为 BouncyCasSTLe 库中的 X509CertSelector

转载 作者:行者123 更新时间:2023-12-01 15:23:31 26 4
gpt4 key购买 nike

我正在尝试验证特定消息是否使用来 self 自己的信任 anchor 识别的实体证书的有效签名进行签名。我正在这样做:

public static boolean isValid(CMSSignedData signedData, X509Certificate rootCert) throws Exception
{
CertStore certsAndCRLs = signedData.getCertificatesAndCRLs("Collection", "BC");
SignerInformationStore signers = signedData.getSignerInfos();
Iterator it = signers.getSigners().iterator();

if (it.hasNext()){
SignerInformation signer = (SignerInformation)it.next();

X509CertSelector signerConstraints = signer.getSID();

PKIXCertPathBuilderResult result = buildPath(rootCert, signerID, certsAndCRLs);

return signer.verify(result.getPublicKey(), "BC");
}
return false;
}

但是这一行给了我一个编译错误:

X509CertSelector signerConstraints = signer.getSID();

因为它无法从 SignerId 转换为 X509CertSelector。我尝试使用显式强制转换:

X509CertSelector signerConstraints = (CertSelector) signer.getSID();

还有:

X509CertSelector signerConstraints = (X509CertSelector) signer.getSID();

没有结果。我怎样才能做到这一点?谢谢

PS:请注意,此代码是从 David Hook 的《Beginning Cryptography with Java》中提取的,但它无法编译。

最佳答案

我昨天解决了我自己的问题。我认为那是某事相对于作为外部存档包含到我的项目中的 .jar。现在,我正在使用这些:

bcprov-jdk16-145.jar
bcmail-jdk16-145.jar

而不是:

bcprov-jdk15on-147.jar
bcmail-jdk15on-147.jar

也许旧版本不支持这种隐式转换。

编辑:David Hook 在 http://bouncy-castle.1462172.n4.nabble.com/Problem-with-SignerID-and-X509CertSelector-td4620461.html 中的回答

Use org.bouncycastle.cert.selector.jcajce.JcaX509CertSelectorConverter - unfortunately the code in "Beginning Cryptography With Java" is now getting out of date. Guess I'll have to get the word processor out again.

Regards,

David

关于java - SignerID 转换为 BouncyCasSTLe 库中的 X509CertSelector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10517148/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com