本文整理汇总了Java中org.bouncycastle.mail.smime.SMIMESigned.getContent方法的典型用法代码示例。如果您正苦于以下问题:Java SMIMESigned.getContent方法的具体用法?Java SMIMESigned.getContent怎么用?Java SMIMESigned.getContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.mail.smime.SMIMESigned
的用法示例。
在下文中一共展示了SMIMESigned.getContent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unsign
import org.bouncycastle.mail.smime.SMIMESigned; //导入方法依赖的package包/类
/**
* Unsigns the encapsulated MIME body part.
*
* @return the an S/MIME message encapsulating the signed content.
* @throws SMimeException if unable to unsign the body part.
*/
public SMimeMessage unsign() throws SMimeException {
try {
setDefaults();
SMIMESigned signed = new SMIMESigned((MimeMultipart)bodyPart.getContent());
MimeBodyPart signedPart = signed.getContent();
if (signedPart == null) {
throw new SMimeException("No signed part");
}
return new SMimeMessage(signedPart, this);
}
catch (Exception e) {
if (e instanceof CMSException) {
e = ((CMSException)e).getUnderlyingException();
}
throw new SMimeException("Unable to unsign body part", e);
}
}
示例2: verify
import org.bouncycastle.mail.smime.SMIMESigned; //导入方法依赖的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);
}
}
示例3: verify
import org.bouncycastle.mail.smime.SMIMESigned; //导入方法依赖的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);
}
}
示例4: testSignedAS2Message
import org.bouncycastle.mail.smime.SMIMESigned; //导入方法依赖的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);
}
示例5: testSignedEncryptedAS2Message
import org.bouncycastle.mail.smime.SMIMESigned; //导入方法依赖的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);
}
示例6: testSignedCommpressMessage
import org.bouncycastle.mail.smime.SMIMESigned; //导入方法依赖的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");
}
}