本文整理汇总了Java中org.bouncycastle.operator.DigestCalculatorProvider类的典型用法代码示例。如果您正苦于以下问题:Java DigestCalculatorProvider类的具体用法?Java DigestCalculatorProvider怎么用?Java DigestCalculatorProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DigestCalculatorProvider类属于org.bouncycastle.operator包,在下文中一共展示了DigestCalculatorProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateOCSPRequest
import org.bouncycastle.operator.DigestCalculatorProvider; //导入依赖的package包/类
/**
* Generates an OCSP request using BouncyCastle.
* @param issuerCert certificate of the issues
* @param serialNumber serial number
* @return an OCSP request
* @throws OCSPException
* @throws IOException
*/
private static OCSPReq generateOCSPRequest(X509Certificate issuerCert, BigInteger serialNumber) throws OCSPException, IOException, OperatorException, CertificateEncodingException {
//Add provider BC
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
JcaDigestCalculatorProviderBuilder digestCalculatorProviderBuilder = new JcaDigestCalculatorProviderBuilder();
DigestCalculatorProvider digestCalculatorProvider = digestCalculatorProviderBuilder.build();
DigestCalculator digestCalculator = digestCalculatorProvider.get(CertificateID.HASH_SHA1);
// Generate the id for the certificate we are looking for
CertificateID id = new CertificateID(digestCalculator, new JcaX509CertificateHolder(issuerCert), serialNumber);
// basic request generation with nonce
OCSPReqBuilder gen = new OCSPReqBuilder();
gen.addRequest(id);
// create details for nonce extension
Extension ext = new Extension(OCSPObjectIdentifiers.id_pkix_ocsp_nonce, false, new DEROctetString(new DEROctetString(PdfEncryption.createDocumentId()).getEncoded()));
gen.setRequestExtensions(new Extensions(new Extension[]{ext}));
return gen.build();
}
示例2: isVerified
import org.bouncycastle.operator.DigestCalculatorProvider; //导入依赖的package包/类
public boolean isVerified(X509CertificateHolder certHolder, DigestCalculatorProvider digesterProvider)
throws CMPException
{
AlgorithmIdentifier digAlg = digestAlgFinder.find(certHolder.toASN1Structure().getSignatureAlgorithm());
if (digAlg == null)
{
throw new CMPException("cannot find algorithm for digest from signature");
}
DigestCalculator digester;
try
{
digester = digesterProvider.get(digAlg);
}
catch (OperatorCreationException e)
{
throw new CMPException("unable to create digester: " + e.getMessage(), e);
}
CMPUtil.derEncodeToStream(certHolder.toASN1Structure(), digester.getOutputStream());
return Arrays.areEqual(certStatus.getCertHash().getOctets(), digester.getDigest());
}
示例3: SignerInfoGenerator
import org.bouncycastle.operator.DigestCalculatorProvider; //导入依赖的package包/类
SignerInfoGenerator(
SignerIdentifier signerIdentifier,
ContentSigner signer,
DigestCalculatorProvider digesterProvider,
CMSSignatureEncryptionAlgorithmFinder sigEncAlgFinder,
CMSAttributeTableGenerator sAttrGen,
CMSAttributeTableGenerator unsAttrGen)
throws OperatorCreationException
{
this.signerIdentifier = signerIdentifier;
this.signer = signer;
if (digesterProvider != null)
{
this.digester = digesterProvider.get(digAlgFinder.find(signer.getAlgorithmIdentifier()));
}
else
{
this.digester = null;
}
this.sAttrGen = sAttrGen;
this.unsAttrGen = unsAttrGen;
this.sigEncAlgFinder = sigEncAlgFinder;
}
示例4: getMessageImprintDigestCalculator
import org.bouncycastle.operator.DigestCalculatorProvider; //导入依赖的package包/类
DigestCalculator getMessageImprintDigestCalculator(DigestCalculatorProvider calculatorProvider)
throws OperatorCreationException
{
TimeStampToken token;
try
{
token = this.getTimeStampToken(timeStamps[0]);
TimeStampTokenInfo info = token.getTimeStampInfo();
ASN1ObjectIdentifier algOID = info.getMessageImprintAlgOID();
DigestCalculator calc = calculatorProvider.get(new AlgorithmIdentifier(algOID));
initialiseMessageImprintDigestCalculator(calc);
return calc;
}
catch (CMSException e)
{
throw new OperatorCreationException("unable to extract algorithm ID: " + e.getMessage(), e);
}
}
示例5: generateOCSPResponse
import org.bouncycastle.operator.DigestCalculatorProvider; //导入依赖的package包/类
private static OCSPResp generateOCSPResponse(PrivateKeyEntry server, PrivateKeyEntry issuer,
CertificateStatus status) throws CertificateException {
try {
X509Certificate serverCertJca = (X509Certificate) server.getCertificate();
X509Certificate caCertJca = (X509Certificate) issuer.getCertificate();
X509CertificateHolder caCert = new JcaX509CertificateHolder(caCertJca);
DigestCalculatorProvider digCalcProv = new BcDigestCalculatorProvider();
BasicOCSPRespBuilder basicBuilder = new BasicOCSPRespBuilder(
SubjectPublicKeyInfo.getInstance(caCertJca.getPublicKey().getEncoded()),
digCalcProv.get(CertificateID.HASH_SHA1));
CertificateID certId = new CertificateID(digCalcProv.get(CertificateID.HASH_SHA1),
caCert, serverCertJca.getSerialNumber());
basicBuilder.addResponse(certId, status);
BasicOCSPResp resp = basicBuilder.build(
new JcaContentSignerBuilder("SHA256withRSA").build(issuer.getPrivateKey()),
null, new Date());
OCSPRespBuilder builder = new OCSPRespBuilder();
return builder.build(OCSPRespBuilder.SUCCESSFUL, resp);
} catch (Exception e) {
throw new CertificateException("cannot generate OCSP response", e);
}
}
示例6: testValidateAllTokens
import org.bouncycastle.operator.DigestCalculatorProvider; //导入依赖的package包/类
public void testValidateAllTokens()
throws Exception
{
DigestCalculatorProvider digestCalculatorProvider = new BcDigestCalculatorProvider();
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
Streams.pipeAll(cmsTimeStampedData.getContent(), bOut);
DigestCalculator imprintCalculator = cmsTimeStampedData.getMessageImprintDigestCalculator(digestCalculatorProvider);
Streams.pipeAll(new ByteArrayInputStream(bOut.toByteArray()), imprintCalculator.getOutputStream());
byte[] digest = imprintCalculator.getDigest();
TimeStampToken[] tokens = cmsTimeStampedData.getTimeStampTokens();
for (int i = 0; i < tokens.length; i++)
{
cmsTimeStampedData.validate(digestCalculatorProvider, digest, tokens[i]);
}
}
示例7: testValidateAllTokens
import org.bouncycastle.operator.DigestCalculatorProvider; //导入依赖的package包/类
public void testValidateAllTokens()
throws Exception
{
DigestCalculatorProvider digestCalculatorProvider = new BcDigestCalculatorProvider();
DigestCalculator imprintCalculator = cmsTimeStampedData.getMessageImprintDigestCalculator(digestCalculatorProvider);
imprintCalculator.getOutputStream().write(cmsTimeStampedData.getContent());
byte[] digest = imprintCalculator.getDigest();
TimeStampToken[] tokens = cmsTimeStampedData.getTimeStampTokens();
for (int i = 0; i < tokens.length; i++)
{
cmsTimeStampedData.validate(digestCalculatorProvider, digest, tokens[i]);
}
}
示例8: SMIMESignedParser
import org.bouncycastle.operator.DigestCalculatorProvider; //导入依赖的package包/类
/**
* Constructor for a signed message with encapsulated content. The encapsulated
* content, if it exists, is written to the file represented by the File object
* passed in.
*
* @param digCalcProvider provider for digest calculators.
* @param message the Part containing the signed content.
* @param file the file the encapsulated part is to be written to after it has been decoded.
*
* @exception MessagingException on an error extracting the signature or
* otherwise processing the message.
* @exception SMIMEException if the body part encapsulated in the message cannot be extracted.
* @exception CMSException if some other problem occurs.
*/
public SMIMESignedParser(
DigestCalculatorProvider digCalcProvider,
Part message,
File file)
throws MessagingException, CMSException, SMIMEException
{
super(digCalcProvider, getInputStream(message));
this.message = message;
CMSTypedStream cont = this.getSignedContent();
if (cont != null)
{
this.content = SMIMEUtil.toMimeBodyPart(cont, file);
}
}
示例9: SMIMESignedParser
import org.bouncycastle.operator.DigestCalculatorProvider; //导入依赖的package包/类
/**
* base constructor for a signed message with encapsulated content.
* <p>
* Note: in this case the encapsulated MimeBody part will only be suitable for a single
* writeTo - once writeTo has been called the file containing the body part will be deleted. If writeTo is not
* called the file will be left in the temp directory.
* </p>
* @param digCalcProvider provider for digest calculators.
* @param message the message containing the encapsulated signed data.
* @exception MessagingException on an error extracting the signature or
* otherwise processing the message.
* @exception SMIMEException if the body part encapsulated in the message cannot be extracted.
* @exception CMSException if some other problem occurs.
*/
public SMIMESignedParser(
DigestCalculatorProvider digCalcProvider,
Part message)
throws MessagingException, CMSException, SMIMEException
{
super(digCalcProvider, getInputStream(message));
this.message = message;
CMSTypedStream cont = this.getSignedContent();
if (cont != null)
{
this.content = SMIMEUtil.toWriteOnceBodyPart(cont);
}
}
示例10: metadataCheck
import org.bouncycastle.operator.DigestCalculatorProvider; //导入依赖的package包/类
private void metadataCheck(byte[] timeStampedData)
throws Exception
{
CMSTimeStampedData cmsTspData = new CMSTimeStampedData(timeStampedData);
DigestCalculatorProvider newCalculatorProvider = new BcDigestCalculatorProvider();
DigestCalculator imprintCalculator = cmsTspData.getMessageImprintDigestCalculator(newCalculatorProvider);
byte[] newContent = cmsTspData.getContent();
assertEquals("Content expected and verified are different", true, Arrays.areEqual(newContent, baseData));
imprintCalculator.getOutputStream().write(newContent);
assertEquals(fileInput, cmsTspData.getFileName());
assertEquals("TXT", cmsTspData.getMediaType());
byte[] digest = imprintCalculator.getDigest();
TimeStampToken[] tokens = cmsTspData.getTimeStampTokens();
assertEquals("TimeStampToken expected and verified are different", 4, tokens.length);
for (int i = 0; i < tokens.length; i++)
{
cmsTspData.validate(newCalculatorProvider, digest, tokens[i]);
}
}
示例11: build
import org.bouncycastle.operator.DigestCalculatorProvider; //导入依赖的package包/类
public CertificateConfirmationContent build(DigestCalculatorProvider digesterProvider)
throws CMPException
{
ASN1EncodableVector v = new ASN1EncodableVector();
for (int i = 0; i != acceptedCerts.size(); i++)
{
X509CertificateHolder certHolder = (X509CertificateHolder)acceptedCerts.get(i);
BigInteger reqID = (BigInteger)acceptedReqIds.get(i);
AlgorithmIdentifier digAlg = digestAlgFinder.find(certHolder.toASN1Structure().getSignatureAlgorithm());
if (digAlg == null)
{
throw new CMPException("cannot find algorithm for digest from signature");
}
DigestCalculator digester;
try
{
digester = digesterProvider.get(digAlg);
}
catch (OperatorCreationException e)
{
throw new CMPException("unable to create digest: " + e.getMessage(), e);
}
CMPUtil.derEncodeToStream(certHolder.toASN1Structure(), digester.getOutputStream());
v.add(new CertStatus(digester.getDigest(), reqID));
}
return new CertificateConfirmationContent(CertConfirmContent.getInstance(new DERSequence(v)), digestAlgFinder);
}
示例12: matchesIssuer
import org.bouncycastle.operator.DigestCalculatorProvider; //导入依赖的package包/类
public boolean matchesIssuer(X509CertificateHolder issuerCert, DigestCalculatorProvider digCalcProvider)
throws OCSPException
{
try
{
return createCertID(digCalcProvider.get(id.getHashAlgorithm()), issuerCert, id.getSerialNumber()).equals(id);
}
catch (OperatorCreationException e)
{
throw new OCSPException("unable to create digest calculator: " + e.getMessage(), e);
}
}
示例13: CMSAuthenticatedData
import org.bouncycastle.operator.DigestCalculatorProvider; //导入依赖的package包/类
public CMSAuthenticatedData(
byte[] authData,
DigestCalculatorProvider digestCalculatorProvider)
throws CMSException
{
this(CMSUtils.readContentInfo(authData), digestCalculatorProvider);
}
示例14: CMSSignedDataParser
import org.bouncycastle.operator.DigestCalculatorProvider; //导入依赖的package包/类
public CMSSignedDataParser(
DigestCalculatorProvider digestCalculatorProvider,
byte[] sigBlock)
throws CMSException
{
this(digestCalculatorProvider, new ByteArrayInputStream(sigBlock));
}
示例15: BcRSASignerInfoVerifierBuilder
import org.bouncycastle.operator.DigestCalculatorProvider; //导入依赖的package包/类
public BcRSASignerInfoVerifierBuilder(CMSSignatureAlgorithmNameGenerator sigAlgNameGen, SignatureAlgorithmIdentifierFinder sigAlgIdFinder, DigestAlgorithmIdentifierFinder digestAlgorithmFinder, DigestCalculatorProvider digestCalculatorProvider)
{
this.sigAlgNameGen = sigAlgNameGen;
this.sigAlgIdFinder = sigAlgIdFinder;
this.contentVerifierProviderBuilder = new BcRSAContentVerifierProviderBuilder(digestAlgorithmFinder);
this.digestCalculatorProvider = digestCalculatorProvider;
}