[英]Error on creating and verifying signed data
I'm using some example code from Wrox Beginning Cryptography with Java . 我正在使用Wrox Beginning Cryptography with Java的一些示例代码。 Line 24 of the code (below) shows me an error in Eclipse. 代码的第24行(下面)显示了Eclipse中的错误。
X509CertSelector signerConstraints = signer.getSID();
Eclipse error: Eclipse错误:
Type mismatch: cannot convert from SignerId to X509CertSelector 类型不匹配:无法从SignerId转换为X509CertSelector
Here is the full example: 这是完整的例子:
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 ..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.