【问题标题】:Error on creating and verifying signed data创建和验证签名数据时出错
【发布时间】:2012-11-22 21:32:49
【问题描述】:

我正在使用来自 Wrox 开始使用 Java 的密码学 中的一些示例代码。代码的第 24 行(如下)显示了 Eclipse 中的一个错误。

X509CertSelector signerConstraints = signer.getSID();

Eclipse 错误:

类型不匹配:无法从 SignerId 转换为 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;
    }
}

【问题讨论】:

  • 请发布该示例代码的链接
  • 您可能需要检查您复制的来源,因为 BouncyCastle documentation for SignerInformation 清楚地将 getSID 的返回类型标识为 SignerID。
  • Nikolay,代码在内容之上,它来自我之前提到的一本书。
  • 我找到了答案:升级到bcprov-jdk16-145.jar, bcmail-jdk16-145.jar..
  • 请回答您自己的问题并接受。

标签: java cryptography bouncycastle


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多