本文整理汇总了Java中org.bouncycastle.cms.DefaultCMSSignatureAlgorithmNameGenerator类的典型用法代码示例。如果您正苦于以下问题:Java DefaultCMSSignatureAlgorithmNameGenerator类的具体用法?Java DefaultCMSSignatureAlgorithmNameGenerator怎么用?Java DefaultCMSSignatureAlgorithmNameGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultCMSSignatureAlgorithmNameGenerator类属于org.bouncycastle.cms包,在下文中一共展示了DefaultCMSSignatureAlgorithmNameGenerator类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: verifyRSASignatures
import org.bouncycastle.cms.DefaultCMSSignatureAlgorithmNameGenerator; //导入依赖的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()));
}
}
}
开发者ID:credentials,项目名称:irma_future_id,代码行数:26,代码来源:BcSignedDataTest.java
示例2: verifyRSASignatures
import org.bouncycastle.cms.DefaultCMSSignatureAlgorithmNameGenerator; //导入依赖的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()));
}
}
}
开发者ID:credentials,项目名称:irma_future_id,代码行数:26,代码来源:NewSignedDataTest.java
示例3: verifyRSASignatures
import org.bouncycastle.cms.DefaultCMSSignatureAlgorithmNameGenerator; //导入依赖的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");
}
}
}
}
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:32,代码来源:BcSignedDataTest.java
示例4: verify
import org.bouncycastle.cms.DefaultCMSSignatureAlgorithmNameGenerator; //导入依赖的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);
}
}
开发者ID:cecid,项目名称:hermes,代码行数:35,代码来源:SFRMMessage.java
示例5: build
import org.bouncycastle.cms.DefaultCMSSignatureAlgorithmNameGenerator; //导入依赖的package包/类
public SignerInformationVerifier build(X509CertificateHolder certHolder)
throws OperatorCreationException, CertificateException
{
return new SignerInformationVerifier(new DefaultCMSSignatureAlgorithmNameGenerator(), new DefaultSignatureAlgorithmIdentifierFinder(), helper.createContentVerifierProvider(certHolder), helper.createDigestCalculatorProvider());
}
开发者ID:Appdome,项目名称:ipack,代码行数:6,代码来源:JcaSimpleSignerInfoVerifierBuilder.java
示例6: verify
import org.bouncycastle.cms.DefaultCMSSignatureAlgorithmNameGenerator; //导入依赖的package包/类
/**
* Verifies the encapsulated MIME body part.
*
* @param cert the certificate for verification.
* @return an S/MIME message encapsulating the signed content.
* @throws SMimeException if unable to verify the body part.
*/
public SMimeMessage verify(X509Certificate cert) throws SMimeException {
try {
if (cert == null) {
throw new SMimeException("No certificate for verification");
}
setDefaults();
SMIMESigned signed = new SMIMESigned((MimeMultipart)bodyPart.getContent());
// CertStore cs = signed.getCertificatesAndCRLs("Collection", "BC");
SignerInformationStore signers = signed.getSignerInfos();
Iterator signerInfos = signers.getSigners().iterator();
while (signerInfos.hasNext()) {
SignerInformation signerInfo = (SignerInformation)signerInfos.next();
// if (!signerInfo.verify(cert, "BC")) { // Deprecated
// TODO: revise the choice of components
SignerInformationVerifier verifier =
new BcRSASignerInfoVerifierBuilder(new DefaultCMSSignatureAlgorithmNameGenerator(),
new DefaultSignatureAlgorithmIdentifierFinder(),
new DefaultDigestAlgorithmIdentifierFinder(),
new BcDigestCalculatorProvider())
.build(new JcaX509CertificateHolder(cert));
if (!signerInfo.verify(verifier)) {
throw new SMimeException("Verification failed");
}
}
MimeBodyPart signedPart = signed.getContent();
if (signedPart == null) {
throw new SMimeException("Unable to extract signed part");
}
else {
return new SMimeMessage(signedPart, this);
}
}
catch (Exception e) {
if (e instanceof CMSException) {
e = ((CMSException)e).getUnderlyingException();
}
throw new SMimeException("Unable to verify body part", e);
}
}
开发者ID:cecid,项目名称:hermes,代码行数:51,代码来源:SMimeMessage.java
示例7: testSignedAS2Message
import org.bouncycastle.cms.DefaultCMSSignatureAlgorithmNameGenerator; //导入依赖的package包/类
@Test
public void testSignedAS2Message() throws Exception{
InputStream ins = FIXTURE_LOADER.getResourceAsStream(MOCK_AS2_MSG);
ByteArrayInputStream bIns = new ByteArrayInputStream(IOHandler.readBytes(ins));
partnershipDVO.setIsOutboundSignRequired(true);
String mid = RANDOM.toString();
AS2Message as2Msg = TARGET.storeOutgoingMessage(
mid, //MessageID
"xml",
partnershipDVO,
new InputStreamDataSource(bIns, "xml", MOCK_AS2_MSG));
//Verify As2Signing Message
try{
SMIMESigned signed = new SMIMESigned((MimeMultipart)as2Msg.getBodyPart().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(partnershipDVO.getEffectiveVerifyCertificate()));
if (!signerInfo.verify(verifier)) {
Assert.fail("Signature Verfifcation Failed");
}
}
//Assert the filename value
MimeBodyPart signedPart = signed.getContent();
String filenameHdr = signedPart.getHeader("Content-Disposition")[0];
Assert.assertEquals("Lost Filename Header Information", MOCK_AS2_MSG, getFileName(filenameHdr));
// Verify MIC Value
ByteArrayOutputStream baos = new ByteArrayOutputStream();
signedPart.writeTo(baos);
byte[] content = (baos.toByteArray());
String mic = calculateMIC(content);
MessageDVO msgDVO = getStoredMessage(mid);
Assert.assertEquals("MIC Value is not valid.", mic, msgDVO.getMicValue());
}catch(Exception exp){
Assert.fail("Signature Verfifcation Failed");
}
Assert.assertTrue(true);
}
开发者ID:cecid,项目名称:hermes,代码行数:55,代码来源:OutgoingMessageProcessorTest.java
示例8: testSignedEncryptedAS2Message
import org.bouncycastle.cms.DefaultCMSSignatureAlgorithmNameGenerator; //导入依赖的package包/类
@Test
public void testSignedEncryptedAS2Message() throws Exception {
InputStream ins = FIXTURE_LOADER.getResourceAsStream(MOCK_AS2_MSG);
ByteArrayInputStream bIns = new ByteArrayInputStream(IOHandler.readBytes(ins));
// Prepare Data
String mid = RANDOM.toString();
partnershipDVO.setIsOutboundEncryptRequired(true);
partnershipDVO.setIsOutboundSignRequired(true);
//Encrypt message
AS2Message as2Msg = TARGET.storeOutgoingMessage(
mid, //MessageID
"xml",
partnershipDVO,
new InputStreamDataSource(bIns, "xml", MOCK_AS2_MSG));
// Decrypt Message
SMIMEEnveloped crypted = new SMIMEEnveloped(as2Msg.getBodyPart());
RecipientId recId = new JceKeyTransRecipientId(partnershipDVO.getEncryptX509Certificate());
RecipientInformationStore recipientsInfo = crypted.getRecipientInfos();
RecipientInformation recipientInfo = recipientsInfo.get(recId);
KeyStoreManager keyMan = (KeyStoreManager)TARGET.getSystemModule().getComponent("keystore-manager");
JceKeyTransEnvelopedRecipient recipient = new JceKeyTransEnvelopedRecipient(keyMan.getPrivateKey());
recipient.setProvider(SECURITY_PROVIDER);
MimeBodyPart decrpted = SMIMEUtil.toMimeBodyPart(recipientInfo.getContent(recipient));
//Verify Signature
try{
SMIMESigned signed = new SMIMESigned((MimeMultipart)decrpted.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(partnershipDVO.getEffectiveVerifyCertificate()));
if (!signerInfo.verify(verifier)) {
Assert.fail("Signature Verfifcation Failed");
}
}
//Assert the filename value
MimeBodyPart signedPart = signed.getContent();
String filenameHdr = signedPart.getHeader("Content-Disposition")[0];
Assert.assertEquals("Lost Filename Header Information", MOCK_AS2_MSG, getFileName(filenameHdr));
// Verify MIC Value
ByteArrayOutputStream baos = new ByteArrayOutputStream();
signedPart.writeTo(baos);
byte[] content = (baos.toByteArray());
String mic = calculateMIC(content);
MessageDVO msgDVO = getStoredMessage(mid);
Assert.assertEquals("MIC Value is not valid.", mic, msgDVO.getMicValue());
}catch(Exception exp){
Assert.fail("Signature Verfifcation Failed");
}
Assert.assertTrue(true);
}
开发者ID:cecid,项目名称:hermes,代码行数:74,代码来源:OutgoingMessageProcessorTest.java
示例9: testSignedCommpressMessage
import org.bouncycastle.cms.DefaultCMSSignatureAlgorithmNameGenerator; //导入依赖的package包/类
@Test
public void testSignedCommpressMessage() throws Exception{
InputStream ins = FIXTURE_LOADER.getResourceAsStream(MOCK_AS2_MSG);
ByteArrayInputStream bIns = new ByteArrayInputStream(IOHandler.readBytes(ins));
// Prepare Data
String mid = RANDOM.toString();
partnershipDVO.setIsOutboundSignRequired(true);
partnershipDVO.setIsOutboundCompressRequired(true);
//Process message
AS2Message as2Msg = TARGET.storeOutgoingMessage(
mid, //MessageID
"xml",
partnershipDVO,
new InputStreamDataSource(bIns, "xml", MOCK_AS2_MSG));
try{
//Verify Message Signature
SMIMESigned signed = new SMIMESigned((MimeMultipart)as2Msg.getBodyPart().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(partnershipDVO.getEffectiveVerifyCertificate()));
if (!signerInfo.verify(verifier)) {
Assert.fail("Signature Verfifcation Failed");
}
}
// Verify MIC Value
MimeBodyPart signedPart = signed.getContent();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
signedPart.writeTo(baos);
byte[] content = (baos.toByteArray());
String mic = calculateMIC(content);
MessageDVO msgDVO = getStoredMessage(mid);
Assert.assertEquals("MIC Value is not valid.", mic, msgDVO.getMicValue());
//Decompress Message
SMIMECompressed compressed = new SMIMECompressed(signedPart);
MimeBodyPart decompressedPart = SMIMEUtil.toMimeBodyPart(compressed.getContent(new ZlibExpanderProvider()));
//Assert the filename value
String filenameHdr = decompressedPart.getHeader("Content-Disposition")[0];
Assert.assertEquals("Lost Filename Header Information", MOCK_AS2_MSG, getFileName(filenameHdr));
}catch(Exception exp){
Assert.fail("Signature Verfifcation Failed");
}
}
开发者ID:cecid,项目名称:hermes,代码行数:59,代码来源:OutgoingMessageProcessorTest.java
示例10: testPythonSigned
import org.bouncycastle.cms.DefaultCMSSignatureAlgorithmNameGenerator; //导入依赖的package包/类
@Test
public void testPythonSigned() throws Exception {
final InputStream pythonIs = Thread.currentThread().getContextClassLoader().getResourceAsStream("python_signed.txt");
/*
Message message = new Message(pythonIs);
Multipart multipart = (Multipart)message.getBody();
System.out.println("count: " + multipart.getCount());
*/
ByteArrayDataSource ds = new ByteArrayDataSource(pythonIs, "multipart/signed");
MimeMultipart mm = new MimeMultipart(ds);
System.out.println(mm.getContentType());
System.out.println("Multipart.count(): " + mm.getCount());
MimeBodyPart mbp = (MimeBodyPart) mm.getBodyPart(0);
output(mbp);
SMIMESigned signed = new SMIMESigned(mm);
SignerInformationStore signers = signed.getSignerInfos();
Assert.assertEquals(1, signers.size());
SignerInformation signer = (SignerInformation) signers.getSigners().iterator().next();
final CMSSignatureAlgorithmNameGenerator cmsSignatureAlgorithmNameGenerator = new DefaultCMSSignatureAlgorithmNameGenerator();
final SignatureAlgorithmIdentifierFinder signatureAlgorithmIdentifierFinder = new DefaultSignatureAlgorithmIdentifierFinder();
final JcaContentVerifierProviderBuilder jcaContentVerifierProviderBuilder = new JcaContentVerifierProviderBuilder();
final ContentVerifierProvider contentVerifierProvider = jcaContentVerifierProviderBuilder.build(cert.getPublicKey());
final DigestCalculatorProvider digestCalculatorProvider = new BcDigestCalculatorProvider();
SignerInformationVerifier verifier = new SignerInformationVerifier(
cmsSignatureAlgorithmNameGenerator,
signatureAlgorithmIdentifierFinder,
contentVerifierProvider,
digestCalculatorProvider);
Assert.assertTrue(signer.verify(verifier));
}
开发者ID:gini,项目名称:jersey-smime,代码行数:43,代码来源:SignedTest.java
注:本文中的org.bouncycastle.cms.DefaultCMSSignatureAlgorithmNameGenerator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论