Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 编译证书验证程序时出错_Java_Digital Signature_Pkcs#7 - Fatal编程技术网

Java 编译证书验证程序时出错

Java 编译证书验证程序时出错,java,digital-signature,pkcs#7,Java,Digital Signature,Pkcs#7,我想用IntelliJIDE编译程序。但它返回以下三个错误: 1.对于此行: CertStore certs = s.getCertificatesAndCRLs("Collection", "BC"); Collection certCollection = certs.getCertificates(signer.getSID()); if (signer.verify(cert.getPublicKey(), "BC")) verified++; import java.io.*;

我想用IntelliJIDE编译程序。但它返回以下三个错误:

1.对于此行:

CertStore certs = s.getCertificatesAndCRLs("Collection", "BC");
Collection certCollection = certs.getCertificates(signer.getSID());
if (signer.verify(cert.getPublicKey(), "BC")) verified++;
import java.io.*;
import java.util.*;
import java.security.*;
import java.security.Security;
import java.security.cert.*;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.cms.*;
此错误:

error: cannot find symbol method getCertificatesAndCRLs(String,String)
error: method getCertificates in class CertStore cannot be applied to given types;
required: CertSelector
found: SignerId
reason: actual argument SignerId cannot be converted to CertSelector by method invocation conversion
error: method verify in class SignerInformation cannot be applied to given types;
required: SignerInformationVerifier
found: PublicKey,String
reason: actual and formal argument lists differ in length
2.对于此行:

CertStore certs = s.getCertificatesAndCRLs("Collection", "BC");
Collection certCollection = certs.getCertificates(signer.getSID());
if (signer.verify(cert.getPublicKey(), "BC")) verified++;
import java.io.*;
import java.util.*;
import java.security.*;
import java.security.Security;
import java.security.cert.*;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.cms.*;
此错误:

error: cannot find symbol method getCertificatesAndCRLs(String,String)
error: method getCertificates in class CertStore cannot be applied to given types;
required: CertSelector
found: SignerId
reason: actual argument SignerId cannot be converted to CertSelector by method invocation conversion
error: method verify in class SignerInformation cannot be applied to given types;
required: SignerInformationVerifier
found: PublicKey,String
reason: actual and formal argument lists differ in length
3.对于这一行:

CertStore certs = s.getCertificatesAndCRLs("Collection", "BC");
Collection certCollection = certs.getCertificates(signer.getSID());
if (signer.verify(cert.getPublicKey(), "BC")) verified++;
import java.io.*;
import java.util.*;
import java.security.*;
import java.security.Security;
import java.security.cert.*;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.cms.*;
此错误:

error: cannot find symbol method getCertificatesAndCRLs(String,String)
error: method getCertificates in class CertStore cannot be applied to given types;
required: CertSelector
found: SignerId
reason: actual argument SignerId cannot be converted to CertSelector by method invocation conversion
error: method verify in class SignerInformation cannot be applied to given types;
required: SignerInformationVerifier
found: PublicKey,String
reason: actual and formal argument lists differ in length

这些是我的程序顶部的导入:

CertStore certs = s.getCertificatesAndCRLs("Collection", "BC");
Collection certCollection = certs.getCertificates(signer.getSID());
if (signer.verify(cert.getPublicKey(), "BC")) verified++;
import java.io.*;
import java.util.*;
import java.security.*;
import java.security.Security;
import java.security.cert.*;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.cms.*;
我将
jdk1.7.0_15
libraries+
bcpkix-jdk15on-151.jar
bcprov-jdk16-1.45.jar
添加到我的项目中


有人能帮我处理这个问题吗?

请按照以下步骤操作。希望它能帮助你,因为它是经过测试的。

步骤01:
从文件中读取字节数组或将数据对象转换为字节数组
示例代码:

FileInputStream fis = new FileInputStream(file);
byte fileContent[] = new byte[(int)file.length()];
fis.read(fileContent);
步骤02:
从字节数组创建CMSSignedData对象
示例代码:

CMSSignedData data = new CMSSignedData(fileContent);
步骤03:
从CMSSignedData获取CertStore
示例代码:

CertStore certs = data.getCertificatesAndCRLs("Collection", "BC");
确保首先在安全性中添加BouncyCastleProvider:

Security.addProvider(new BouncyCastleProvider());'
步骤04:
使用签名者信息获取证书集合
示例代码:

SignerInformation signer = (SignerInformation) i.next();
Collection<? extends Certificate> certCollection = certs.getCertificates(signer.getSID());
if (signer.verify(new JcaSimpleSignerInfoVerifierBuilder().setProvider("BC").build(cert)) ) 
{   
     }


为了实现目标,请检查您是否已完成上述步骤。


我猜,要么是您使用错误的数据输入生成CMSSignedData,要么是相关库相互冲突(最可能的原因)。我使用了bcprov-jdk16-1.46.jarbcmail-jdk16-1.46.jar来完成所有任务。

请按照以下步骤操作。希望它能帮助你,因为它是经过测试的。

步骤01:
从文件中读取字节数组或将数据对象转换为字节数组
示例代码:

FileInputStream fis = new FileInputStream(file);
byte fileContent[] = new byte[(int)file.length()];
fis.read(fileContent);
步骤02:
从字节数组创建CMSSignedData对象
示例代码:

CMSSignedData data = new CMSSignedData(fileContent);
步骤03:
从CMSSignedData获取CertStore
示例代码:

CertStore certs = data.getCertificatesAndCRLs("Collection", "BC");
确保首先在安全性中添加BouncyCastleProvider:

Security.addProvider(new BouncyCastleProvider());'
步骤04:
使用签名者信息获取证书集合
示例代码:

SignerInformation signer = (SignerInformation) i.next();
Collection<? extends Certificate> certCollection = certs.getCertificates(signer.getSID());
if (signer.verify(new JcaSimpleSignerInfoVerifierBuilder().setProvider("BC").build(cert)) ) 
{   
     }


为了实现目标,请检查您是否已完成上述步骤。


我猜,要么是您使用错误的数据输入生成CMSSignedData,要么是相关库相互冲突(最可能的原因)。我已经使用了bcprov-jdk16-1.46.jarbcmail-jdk16-1.46.jar来完成所有任务。

也许你应该问问[本程序]的作者(关于正确的库。引用:“上面的示例是使用j2sdk1.4.1_02编译的,编译和运行时都需要Bouncy Castle base provider和mail provider版本1.19+。”此示例(创建于10年前)使用一个非常古老的BooCyCar版本;我假设API与最新版本不同。请考虑寻找一个更新的功能示例。也许你应该问[这个程序]的作者(关于正确的库。引用:上面的示例是用j2sdk1.4.1_02编译的,编译和运行时都需要Bouncy Castle base provider和mail provider 1.19+版本使用一个非常古老的BooCyScript版本;我假设API与最新版本不同。请考虑寻找更新的功能示例。