java - 创建和验证签名数据时出错

标签 java cryptography bouncycastle

我正在使用 Wrox Beginning Cryptography with Java 中的一些示例代码。代码的第 24 行(下方)向我展示了 Eclipse 中的一个错误。

X509CertSelector signerConstraints = signer.getSID();

eclipse 错误:

Type mismatch: cannot convert from SignerId to X509CertSelector

这里是完整的例子:

package chapter9;

import java.security.cert.*;
import java.util.Iterator;

import org.bouncycastle.cms.CMSSignedData;
import org.bouncycastle.cms.SignerInformation;
import org.bouncycastle.cms.SignerInformationStore;

/**
 * Base class for signed examples.
 */
public class SignedDataProcessor {
    /**
     * Return a boolean array representing keyUsage with digitalSignature set.
     */
    static boolean[] getKeyUsageForSignature() {
        boolean[] val = new boolean[9];
        val[0] = true;

        return val;
    }

    /**
     * Take a CMS SignedData message and a trust anchor and determine if
     * the message is signed with a valid signature from a end entity
     * entity certificate recognized by the trust anchor rootCert.
     */
     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();

            signerConstraints.setKeyUsage(getKeyUsageForSignature());

            PKIXCertPathBuilderResult result = 
                Utils.buildPath(rootCert, signer.getSID(), certsAndCRLs);

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

        return false;
    }
}

最佳答案

我找到了答案:只需升级到 bcprov-jdk16-145.jar、bcmail-jdk16-145.jar..

关于java - 创建和验证签名数据时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13446852/

相关文章:

java - 充气城堡 : Signed Certificate with an existing CA

java - 多个 @Pattern 表现得像 OR 操作

java - Eclipse无法解决

c# - 我将如何在 PHP 中生成相同的 token ? (来自.NET)

encryption - 使用 RSA-1024 签名 SHA-256 摘要 : what is the size?

php - Crypt() 函数的河豚盐长度?

c# - 如何在保留私钥的同时将 BouncyCaSTLe X509Certificate 转换为 .NET Standard X509Certificate2?

java - 如何使用带有 JBOSS 工具的 Hibernate 在数据库中添加新记录?

Java:避免阶乘溢出

java - 使用 bouncycaSTLe/spongycaSTLe 读取加密私钥