本文整理汇总了Java中org.bouncycastle.operator.bc.BcDigestCalculatorProvider类的典型用法代码示例。如果您正苦于以下问题:Java BcDigestCalculatorProvider类的具体用法?Java BcDigestCalculatorProvider怎么用?Java BcDigestCalculatorProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BcDigestCalculatorProvider类属于org.bouncycastle.operator.bc包,在下文中一共展示了BcDigestCalculatorProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyRSASignatures
import org.bouncycastle.operator.bc.BcDigestCalculatorProvider; //导入依赖的package包/类
private void verifyRSASignatures(CMSSignedData s, byte[] contentDigest)
throws Exception
{
Store certStore = s.getCertificates();
SignerInformationStore signers = s.getSignerInfos();
Collection c = signers.getSigners();
Iterator it = c.iterator();
while (it.hasNext())
{
SignerInformation signer = (SignerInformation)it.next();
Collection certCollection = certStore.getMatches(signer.getSID());
Iterator certIt = certCollection.iterator();
X509CertificateHolder cert = (X509CertificateHolder)certIt.next();
assertEquals(true, signer.verify(new BcRSASignerInfoVerifierBuilder(new DefaultCMSSignatureAlgorithmNameGenerator(), new DefaultSignatureAlgorithmIdentifierFinder(), new DefaultDigestAlgorithmIdentifierFinder(), new BcDigestCalculatorProvider()).build(cert)));
if (contentDigest != null)
{
assertTrue(MessageDigest.isEqual(contentDigest, signer.getContentDigest()));
}
}
}
示例2: generateOCSPResponse
import org.bouncycastle.operator.bc.BcDigestCalculatorProvider; //导入依赖的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);
}
}
示例3: generateOcspRequest
import org.bouncycastle.operator.bc.BcDigestCalculatorProvider; //导入依赖的package包/类
private OCSPReq generateOcspRequest(X509Certificate issuerCert,
BigInteger serialNumber) throws OCSPException, CertificateEncodingException, OperatorCreationException, IOException {
BcDigestCalculatorProvider util = new BcDigestCalculatorProvider();
// Generate the id for the certificate we are looking for
CertificateID id = new CertificateID(util.get( CertificateID.HASH_SHA1),
new X509CertificateHolder(issuerCert.getEncoded()), serialNumber);
OCSPReqBuilder ocspGen = new OCSPReqBuilder();
ocspGen.addRequest(id);
BigInteger nonce = BigInteger.valueOf(System.currentTimeMillis());
Extension ext = new Extension(OCSPObjectIdentifiers.id_pkix_ocsp_nonce, true, new DEROctetString(nonce.toByteArray()));
ocspGen.setRequestExtensions(new Extensions(new Extension[] { ext }));
return ocspGen.build();
}
示例4: ECShuffledTranscriptVerifier
import org.bouncycastle.operator.bc.BcDigestCalculatorProvider; //导入依赖的package包/类
/**
* Base Constructor.
*
* @param pubKey the public key we are verifying against.
* @param witnessTranscript transcript of witness values.
* @param initialTranscript transcript of shuffle input.
* @param finalTranscript transcript of shuffle output.
* @throws IOException if any of the transcripts cannot be successfully parsed.
*/
public ECShuffledTranscriptVerifier(ECPublicKeyParameters pubKey, InputStream witnessTranscript, InputStream initialTranscript, InputStream finalTranscript)
throws IOException
{
this.pubKey = pubKey;
this.ecCurve = pubKey.getParameters().getCurve();
try
{
//
// we read the witnesses first as there is no need to load messages from the others if they
// are not referenced here.
//
CMSSignedDataParser cmsParser = new CMSSignedDataParser(new BcDigestCalculatorProvider(), witnessTranscript);
this.witnessTranscript = new ASN1InputStream(cmsParser.getSignedContent().getContentStream());
this.initialTranscript = initialTranscript;
this.finalTranscript = finalTranscript;
}
catch (Exception e)
{
throw new IOException("Unable to parse transcripts: " + e.getMessage(), e);
}
}
示例5: verifyRSASignatures
import org.bouncycastle.operator.bc.BcDigestCalculatorProvider; //导入依赖的package包/类
private void verifyRSASignatures(CMSSignedData s, byte[] contentDigest)
throws Exception
{
Store certStore = s.getCertificates();
SignerInformationStore signers = s.getSignerInfos();
Collection c = signers.getSigners();
Iterator it = c.iterator();
while (it.hasNext())
{
SignerInformation signer = (SignerInformation)it.next();
Collection certCollection = certStore.getMatches(signer.getSID());
Iterator certIt = certCollection.iterator();
X509CertificateHolder cert = (X509CertificateHolder)certIt.next();
assertEquals(true, signer.verify(new BcRSASignerInfoVerifierBuilder(new DefaultCMSSignatureAlgorithmNameGenerator(), new DefaultSignatureAlgorithmIdentifierFinder(), new DefaultDigestAlgorithmIdentifierFinder(), new BcDigestCalculatorProvider()).build(cert)));
if (contentDigest != null)
{
assertTrue(MessageDigest.isEqual(contentDigest, signer.getContentDigest()));
}
}
}
示例6: metadataCheck
import org.bouncycastle.operator.bc.BcDigestCalculatorProvider; //导入依赖的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]);
}
}
示例7: testValidateAllTokens
import org.bouncycastle.operator.bc.BcDigestCalculatorProvider; //导入依赖的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: testValidateAllTokens
import org.bouncycastle.operator.bc.BcDigestCalculatorProvider; //导入依赖的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]);
}
}
示例9: verifyRSASignatures
import org.bouncycastle.operator.bc.BcDigestCalculatorProvider; //导入依赖的package包/类
private void verifyRSASignatures(CMSSignedData s, byte[] contentDigest)
throws Exception
{
Store certStore = s.getCertificates();
SignerInformationStore signers = s.getSignerInfos();
Collection c = signers.getSigners();
Iterator it = c.iterator();
while (it.hasNext())
{
SignerInformation signer = (SignerInformation)it.next();
Collection certCollection = certStore.getMatches(signer.getSID());
Iterator certIt = certCollection.iterator();
X509CertificateHolder cert = (X509CertificateHolder)certIt.next();
if (!signer.verify(new BcRSASignerInfoVerifierBuilder(new DefaultCMSSignatureAlgorithmNameGenerator(), new DefaultSignatureAlgorithmIdentifierFinder(), new DefaultDigestAlgorithmIdentifierFinder(), new BcDigestCalculatorProvider()).build(cert)))
{
fail("signature verification failed");
}
if (contentDigest != null)
{
if (!Arrays.areEqual(contentDigest, signer.getContentDigest()))
{
fail("digest verification failed");
}
}
}
}
示例10: verify
import org.bouncycastle.operator.bc.BcDigestCalculatorProvider; //导入依赖的package包/类
public void verify(X509Certificate cert) throws SFRMException {
try {
SMIMESigned signed = new SMIMESigned((MimeMultipart)bodyPart.getContent());
SignerInformationStore signers = signed.getSignerInfos();
Iterator signerInfos = signers.getSigners().iterator();
while (signerInfos.hasNext()) {
SignerInformation signerInfo = (SignerInformation)signerInfos.next();
SignerInformationVerifier verifier =
new BcRSASignerInfoVerifierBuilder(new DefaultCMSSignatureAlgorithmNameGenerator(),
new DefaultSignatureAlgorithmIdentifierFinder(),
new DefaultDigestAlgorithmIdentifierFinder(),
new BcDigestCalculatorProvider())
.build(new JcaX509CertificateHolder(cert));
if (!signerInfo.verify(verifier)) {
throw new SFRMMessageException("Verification failed");
}
}
MimeBodyPart signedPart = signed.getContent();
if (signedPart == null) {
throw new SFRMMessageException("Unable to extract signed part");
}
else {
this.bodyPart = signedPart;
this.setIsSigned(true);
}
} catch (org.bouncycastle.cms.CMSException ex) {
throw new SFRMException("Unable to verify body part", ex.getUnderlyingException());
} catch (Exception e) {
throw new SFRMException("Unable to verify body part", e);
}
}
示例11: signWithSeparatedHashing
import org.bouncycastle.operator.bc.BcDigestCalculatorProvider; //导入依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/41767351/create-pkcs7-signature-from-file-digest">
* Create pkcs7 signature from file digest
* </a>
* <p>
* The OP's <code>sign</code> method after fixing some errors. The
* OP's original method is {@link #signBySnox(InputStream)}. The
* errors were
* </p>
* <ul>
* <li>multiple attempts at reading the {@link InputStream} parameter;
* <li>convoluted creation of final CMS container.
* </ul>
* <p>
* Additionally this method uses SHA256 instead of SHA-1.
* </p>
*/
public byte[] signWithSeparatedHashing(InputStream content) throws IOException
{
try
{
// Digest generation step
MessageDigest md = MessageDigest.getInstance("SHA256", "BC");
byte[] digest = md.digest(IOUtils.toByteArray(content));
// Separate signature container creation step
List<Certificate> certList = Arrays.asList(chain);
JcaCertStore certs = new JcaCertStore(certList);
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
Attribute attr = new Attribute(CMSAttributes.messageDigest,
new DERSet(new DEROctetString(digest)));
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(attr);
SignerInfoGeneratorBuilder builder = new SignerInfoGeneratorBuilder(new BcDigestCalculatorProvider())
.setSignedAttributeGenerator(new DefaultSignedAttributeTableGenerator(new AttributeTable(v)));
AlgorithmIdentifier sha256withRSA = new DefaultSignatureAlgorithmIdentifierFinder().find("SHA256withRSA");
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
InputStream in = new ByteArrayInputStream(chain[0].getEncoded());
X509Certificate cert = (X509Certificate) certFactory.generateCertificate(in);
gen.addSignerInfoGenerator(builder.build(
new BcRSAContentSignerBuilder(sha256withRSA,
new DefaultDigestAlgorithmIdentifierFinder().find(sha256withRSA))
.build(PrivateKeyFactory.createKey(pk.getEncoded())),
new JcaX509CertificateHolder(cert)));
gen.addCertificates(certs);
CMSSignedData s = gen.generate(new CMSAbsentContent(), false);
return s.getEncoded();
}
catch (Exception e)
{
e.printStackTrace();
throw new IOException(e);
}
}
示例12: addKeyIdentifiers
import org.bouncycastle.operator.bc.BcDigestCalculatorProvider; //导入依赖的package包/类
private void addKeyIdentifiers(SubjectPublicKeyInfo subjectPubKeyInfo, SubjectPublicKeyInfo issuerPubKeyInfo, X509v3CertificateBuilder v3CertGen) throws OperatorCreationException, CertIOException {
DigestCalculator digCalc = new BcDigestCalculatorProvider().get(new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1));
X509ExtensionUtils x509ExtensionUtils = new X509ExtensionUtils(digCalc);
v3CertGen.addExtension(Extension.subjectKeyIdentifier, false, x509ExtensionUtils.createSubjectKeyIdentifier(subjectPubKeyInfo));
v3CertGen.addExtension(Extension.authorityKeyIdentifier, false, x509ExtensionUtils.createAuthorityKeyIdentifier(issuerPubKeyInfo));
}
示例13: getSignerInfoGeneratorBuilder
import org.bouncycastle.operator.bc.BcDigestCalculatorProvider; //导入依赖的package包/类
/**
* @param signedAttributeGenerator
* the signedAttribute generator
* @param unsignedAttributeGenerator
* the unsignedAttribute generator
* @return a SignerInfoGeneratorBuilder that generate the signed and unsigned attributes according to the parameters
*/
private SignerInfoGeneratorBuilder getSignerInfoGeneratorBuilder(DefaultSignedAttributeTableGenerator signedAttributeGenerator,
SimpleAttributeTableGenerator unsignedAttributeGenerator) {
final DigestCalculatorProvider digestCalculatorProvider = new BcDigestCalculatorProvider();
SignerInfoGeneratorBuilder sigInfoGeneratorBuilder = new SignerInfoGeneratorBuilder(digestCalculatorProvider);
sigInfoGeneratorBuilder.setSignedAttributeGenerator(signedAttributeGenerator);
sigInfoGeneratorBuilder.setUnsignedAttributeGenerator(unsignedAttributeGenerator);
return sigInfoGeneratorBuilder;
}
示例14: getAndCheckBoardSize
import org.bouncycastle.operator.bc.BcDigestCalculatorProvider; //导入依赖的package包/类
/**
* Return the number of messages that were on the board producing these commitments.
*
* @param fileList list of general transcript files.
* @return number of messages on the board.
* @throws TranscriptVerificationException if there is a mismatch in the file size.
*/
public static int getAndCheckBoardSize(File[] fileList)
throws TranscriptVerificationException
{
int boardSize = -1;
for (File file : fileList)
{
int count = 0;
try
{
CMSSignedDataParser cmsParser = new CMSSignedDataParser(new BcDigestCalculatorProvider(), new BufferedInputStream(new FileInputStream(file)));
ASN1InputStream aIn = new ASN1InputStream(cmsParser.getSignedContent().getContentStream());
while (aIn.readObject() != null)
{
count++;
}
if (boardSize == -1)
{
boardSize = count;
}
else if (count != boardSize)
{
throw new TranscriptVerificationException("Size mismatch in commitment files: " + file.getPath());
}
cmsParser.close();
}
catch (Exception e)
{
throw new TranscriptVerificationException("Size check failed on " + file.getPath() + ": " + e.getMessage(), e);
}
}
return boardSize;
}
示例15: getSequence
import org.bouncycastle.operator.bc.BcDigestCalculatorProvider; //导入依赖的package包/类
private byte[] getSequence(byte[] init, MessageChooser chooser)
throws Exception
{
CMSSignedDataParser cmsParser = new CMSSignedDataParser(new BcDigestCalculatorProvider(), new ByteArrayInputStream(init));
ASN1InputStream aIn = new ASN1InputStream(cmsParser.getSignedContent().getContentStream());
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
CMSSignedDataStreamGenerator cmsGen = new CMSSignedDataStreamGenerator();
OutputStream outputStream = cmsGen.open(bOut, true);
DEROutputStream dOut = new DEROutputStream(outputStream);
ASN1Primitive obj;
int count = 0;
while ((obj = aIn.readObject()) != null)
{
if (chooser.chooseMessage(count++))
{
dOut.writeObject(obj);
}
}
dOut.close();
cmsParser.close();
outputStream.close();
return bOut.toByteArray();
}