• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SMIMEEnveloped类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.bouncycastle.mail.smime.SMIMEEnveloped的典型用法代码示例。如果您正苦于以下问题:Java SMIMEEnveloped类的具体用法?Java SMIMEEnveloped怎么用?Java SMIMEEnveloped使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SMIMEEnveloped类属于org.bouncycastle.mail.smime包,在下文中一共展示了SMIMEEnveloped类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: decrypt

import org.bouncycastle.mail.smime.SMIMEEnveloped; //导入依赖的package包/类
public void decrypt(X509Certificate cert, PrivateKey privateKey) throws SFRMException {
    try {
        SMIMEEnveloped m = new SMIMEEnveloped(bodyPart);

 RecipientId recId = new JceKeyTransRecipientId(cert);

 RecipientInformationStore  recipientsInfo = m.getRecipientInfos();	
 RecipientInformation       recipientInfo = recipientsInfo.get(recId);

        if (recipientInfo == null) {
            throw new SFRMMessageException("Invalid encrypted content");
        }

 JceKeyTransEnvelopedRecipient recipient = new JceKeyTransEnvelopedRecipient(privateKey);
 recipient.setProvider(SECURITY_PROVIDER);							
 
        this.bodyPart = new MimeBodyPart(new ByteArrayInputStream(recipientInfo.getContent(recipient)));
        this.setIsEncrypted(true);
	} catch (org.bouncycastle.cms.CMSException ex) {
		throw new SFRMException("Unable to decrypt body part", ex.getUnderlyingException());
    } catch (Exception e) {
        throw new SFRMException("Unable to decrypt body part", e);
    }
}
 
开发者ID:cecid,项目名称:hermes,代码行数:25,代码来源:SFRMMessage.java


示例2: decryptPart

import org.bouncycastle.mail.smime.SMIMEEnveloped; //导入依赖的package包/类
private MimeBodyPart decryptPart(MimeBodyPart part) throws Exception {

        SMIMEEnveloped smimeEnveloped = new SMIMEEnveloped(part);
        RecipientInformationStore recipients = smimeEnveloped.getRecipientInfos();
        RecipientInformation recipient = recipients.get(recId);

        if (null == recipient) {
            StringBuilder errorMessage = new StringBuilder();
            errorMessage.append("This email wasn't encrypted with \"" + recId.toString() + "\".\n");
            errorMessage.append("The encryption recId is: ");

            for (Object rec : recipients.getRecipients()) {
                if (rec instanceof RecipientInformation) {
                    RecipientId recipientId = ((RecipientInformation) rec).getRID();
                    errorMessage.append("\"" + recipientId.toString() + "\"\n");
                }
            }
            throw new Exception(errorMessage.toString());
        }

        return toMimeBodyPart(recipient.getContent(ks.getKey(decryptionKeyAlias, null), BOUNCY_CASTLE_PROVIDER));
    }
 
开发者ID:CloudSlang,项目名称:cs-actions,代码行数:23,代码来源:GetMailMessage.java


示例3: decryptMimeBodyPart

import org.bouncycastle.mail.smime.SMIMEEnveloped; //导入依赖的package包/类
public static MimeBodyPart decryptMimeBodyPart(MimeBodyPart mbp, 
								KeyStore ks, char[] password)
	throws Exception
{
	SMIMEEnveloped enveloped = new SMIMEEnveloped(mbp);
	Enumeration<String> aliases = ks.aliases();
	
	while (aliases.hasMoreElements())
	{
		String alias = aliases.nextElement();
		if (ks.isKeyEntry(alias))
		{    			
			MimeBodyPart decrypted = decryptEnvelope(enveloped, 
					ks.getKey(alias, password), (X509Certificate) ks.getCertificate(alias));
			if (decrypted != null)
				return decrypted;
		}    			
	}
	
	return null;
}
 
开发者ID:edeoliveira,项目名称:Mailster,代码行数:22,代码来源:SmimeUtilities.java


示例4: decryptEnvelope

import org.bouncycastle.mail.smime.SMIMEEnveloped; //导入依赖的package包/类
/**
 * Try to decrypt the provided envelope with the provided certificate 
 * and private key. 
 */
public static MimeBodyPart decryptEnvelope(SMIMEEnveloped enveloped, 
							Key key, X509Certificate cert)
	throws Exception
{
	 // look for our recipient identifier
    RecipientId recId = new RecipientId();
    recId.setSerialNumber(cert.getSerialNumber());
    recId.setIssuer(cert.getIssuerX500Principal().getEncoded());

    RecipientInformationStore recipients = enveloped.getRecipientInfos();
    RecipientInformation recipient = recipients.get(recId);

    // decryption step
	if (recipient != null)
		return SMIMEUtil.toMimeBodyPart(recipient.getContent(key, "BC"));
	else
		return null;
}
 
开发者ID:edeoliveira,项目名称:Mailster,代码行数:23,代码来源:SmimeUtilities.java


示例5: verifyAlgorithm

import org.bouncycastle.mail.smime.SMIMEEnveloped; //导入依赖的package包/类
private void verifyAlgorithm(
    String algorithmOid,
    MimeBodyPart msg) 
    throws Exception
{
    SMIMEEnvelopedGenerator  gen = new SMIMEEnvelopedGenerator();
      
    gen.addKeyTransRecipient(_reciCert);
     
    //
    // generate a MimeBodyPart object which encapsulates the content
    // we want encrypted.
    //

    MimeBodyPart   mp = gen.generate(msg, algorithmOid, "BC");
    SMIMEEnveloped m = new SMIMEEnveloped(mp);
    RecipientId    recId = getRecipientId(_reciCert);

    RecipientInformationStore  recipients = m.getRecipientInfos();
    RecipientInformation       recipient = recipients.get(recId);

    MimeBodyPart    res = SMIMEUtil.toMimeBodyPart(recipient.getContent(_reciKP.getPrivate(), "BC"));

    verifyMessageBytes(msg, res);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:26,代码来源:SMIMEEnvelopedTest.java


示例6: testBrokenEnvelope

import org.bouncycastle.mail.smime.SMIMEEnveloped; //导入依赖的package包/类
public void testBrokenEnvelope()
    throws Exception
{
    Session session = Session.getDefaultInstance(System.getProperties(), null);
    MimeMessage msg = new MimeMessage(session, getClass().getResourceAsStream("brokenEnv.message"));

    try
    {
        new SMIMEEnveloped(msg);
    }
    catch (CMSException e)
    {
        if (!e.getMessage().equals("Malformed content."))
        {
            fail("wrong exception on bogus envelope");
        }
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:19,代码来源:SMIMEMiscTest.java


示例7: verifyAlgorithm

import org.bouncycastle.mail.smime.SMIMEEnveloped; //导入依赖的package包/类
private void verifyAlgorithm(
    String algorithmOid,
    MimeBodyPart msg) 
    throws Exception
{
    SMIMEEnvelopedGenerator  gen = new SMIMEEnvelopedGenerator();
      
    gen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(_reciCert).setProvider(BC));
     
    //
    // generate a MimeBodyPart object which encapsulates the content
    // we want encrypted.
    //

    MimeBodyPart   mp = gen.generate(msg, new JceCMSContentEncryptorBuilder(new ASN1ObjectIdentifier(algorithmOid)).setProvider(BC).build());
    SMIMEEnveloped m = new SMIMEEnveloped(mp);
    RecipientId    recId = getRecipientId(_reciCert);

    RecipientInformationStore  recipients = m.getRecipientInfos();
    RecipientInformation       recipient = recipients.get(recId);

    MimeBodyPart    res = SMIMEUtil.toMimeBodyPart(recipient.getContent(new JceKeyTransEnvelopedRecipient(_reciKP.getPrivate()).setProvider(BC)));

    verifyMessageBytes(msg, res);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:26,代码来源:NewSMIMEEnvelopedTest.java


示例8: getEntity

import org.bouncycastle.mail.smime.SMIMEEnveloped; //导入依赖的package包/类
public Object getEntity(Class t, Type gt, Annotation[] ann, PrivateKey pKey, X509Certificate cert) {
    final MimeBodyPart decrypted;

    try {
        MimeBodyPart encryptedBodyPartBase64 = body;
        SMIMEEnveloped m = new SMIMEEnveloped(encryptedBodyPartBase64);
        JceKeyTransRecipientId recId = new JceKeyTransRecipientId(cert);

        RecipientInformationStore recipients = m.getRecipientInfos();
        RecipientInformation recipientInfo = recipients.get(recId);
        Recipient recipient = new JceKeyTransEnvelopedRecipient(pKey).setProvider("BC");

        decrypted = SMIMEUtil.toMimeBodyPart(recipientInfo.getContent(recipient));
    } catch (Exception e1) {
        throw new RuntimeException(e1);
    }

    return extractEntity(t, gt, ann, decrypted, providers);
}
 
开发者ID:gini,项目名称:jersey-smime,代码行数:20,代码来源:EnvelopedInputImpl.java


示例9: testCapEncrypt

import org.bouncycastle.mail.smime.SMIMEEnveloped; //导入依赖的package包/类
public void testCapEncrypt()
    throws Exception
{
    MimeBodyPart    _msg      = SMIMETestUtil.makeMimeBodyPart("WallaWallaWashington");

    SMIMEEnvelopedGenerator   gen = new SMIMEEnvelopedGenerator();

    //
    // create a subject key id - this has to be done the same way as
    // it is done in the certificate associated with the private key
    //
    MessageDigest           dig = MessageDigest.getInstance("SHA1", "BC");
    dig.update(_reciCert.getPublicKey().getEncoded());

      
    gen.addKeyTransRecipient(_reciCert.getPublicKey(), dig.digest());
     
    //
    // generate a MimeBodyPart object which encapsulates the content
    // we want encrypted.
    //
    MimeBodyPart mp = gen.generate(_msg, SMIMEEnvelopedGenerator.RC2_CBC, 40, "BC");

    SMIMEEnveloped       m = new SMIMEEnveloped(mp);

    dig.update(_reciCert.getPublicKey().getEncoded());

    RecipientId          recId = new KeyTransRecipientId(dig.digest());

    RecipientInformationStore  recipients = m.getRecipientInfos();
    RecipientInformation       recipient = recipients.get(recId);

    MimeBodyPart    res = SMIMEUtil.toMimeBodyPart(recipient.getContent(_reciKP.getPrivate(), "BC"));

    verifyMessageBytes(_msg, res);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:37,代码来源:SMIMEEnvelopedTest.java


示例10: testQuotePrintableSigPreservation

import org.bouncycastle.mail.smime.SMIMEEnveloped; //导入依赖的package包/类
public void testQuotePrintableSigPreservation()
    throws Exception
{
    MimeMessage msg = new MimeMessage((Session)null, getClass().getResourceAsStream("qp-soft-break.eml"));

    SMIMEEnvelopedGenerator  encGen = new SMIMEEnvelopedGenerator();

    encGen.addKeyTransRecipient(origCert);

    MimeBodyPart   mp = encGen.generate(msg, SMIMEEnvelopedGenerator.AES128_CBC, "BC");

    SMIMEEnveloped       env = new SMIMEEnveloped(mp);
    RecipientInformation ri = (RecipientInformation)env.getRecipientInfos().getRecipients().iterator().next();
    MimeBodyPart         mm = SMIMEUtil.toMimeBodyPart(ri.getContentStream(origKP.getPrivate(), "BC"));
    SMIMESigned          s = new SMIMESigned((MimeMultipart)mm.getContent());
    Collection           c = s.getSignerInfos().getSigners();
    Iterator             it = c.iterator();
    CertStore            certs = s.getCertificatesAndCRLs("Collection", "BC");

    while (it.hasNext())
    {
        SignerInformation   signer = (SignerInformation)it.next();
        Collection          certCollection = certs.getCertificates(selectorConverter.getCertSelector(signer.getSID()));

        Iterator        certIt = certCollection.iterator();
        X509Certificate cert = (X509Certificate)certIt.next();

        assertEquals(true, signer.verify(cert, "BC"));
    }

    ((FileBackedMimeBodyPart)mm).dispose();
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:33,代码来源:SMIMEMiscTest.java


示例11: testDotNetEncMailMatch

import org.bouncycastle.mail.smime.SMIMEEnveloped; //导入依赖的package包/类
public void testDotNetEncMailMatch()
    throws Exception
{
    MimeMessage message = loadMessage("dotnet_encrypted_mail.eml");

    SMIMEEnveloped env = new SMIMEEnveloped(message);

    RecipientInformationStore store = env.getRecipientInfos();

    assertNotNull(store.get(new JceKeyTransRecipientId(loadCert("dotnet_enc_cert.pem"))));
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:12,代码来源:NewSMIMEEnvelopedTest.java


示例12: testCapEncrypt

import org.bouncycastle.mail.smime.SMIMEEnveloped; //导入依赖的package包/类
public void testCapEncrypt()
    throws Exception
{
    MimeBodyPart    msg      = SMIMETestUtil.makeMimeBodyPart("WallaWallaWashington");

    SMIMEEnvelopedGenerator   gen = new SMIMEEnvelopedGenerator();

    //
    // create a subject key id - this has to be done the same way as
    // it is done in the certificate associated with the private key
    //
    MessageDigest           dig = MessageDigest.getInstance("SHA1", BC);

    dig.update(_reciCert.getPublicKey().getEncoded());

    gen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(dig.digest(), _reciCert.getPublicKey()).setProvider(BC));
     
    //
    // generate a MimeBodyPart object which encapsulates the content
    // we want encrypted.
    //
    MimeBodyPart mp = gen.generate(msg, new JceCMSContentEncryptorBuilder(CMSAlgorithm.RC2_CBC, 40).setProvider(BC).build());

    SMIMEEnveloped       m = new SMIMEEnveloped(mp);

    dig.update(_reciCert.getPublicKey().getEncoded());

    RecipientId          recId = new KeyTransRecipientId(dig.digest());

    RecipientInformationStore  recipients = m.getRecipientInfos();
    RecipientInformation       recipient = recipients.get(recId);

    MimeBodyPart    res = SMIMEUtil.toMimeBodyPart(recipient.getContent(new JceKeyTransEnvelopedRecipient(_reciKP.getPrivate()).setProvider(BC)));

    verifyMessageBytes(msg, res);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:37,代码来源:NewSMIMEEnvelopedTest.java


示例13: decode2Mime

import org.bouncycastle.mail.smime.SMIMEEnveloped; //导入依赖的package包/类
private MimeBodyPart decode2Mime(MimeBodyPart mp) throws MessagingException, CMSException, SMIMEException {
    final Recipient recipient = new JceKeyTransEnvelopedRecipient(privateKey);
    final RecipientId recipientId = new JceKeyTransRecipientId(cert);

    final SMIMEEnveloped m = new SMIMEEnveloped(mp);
    final RecipientInformationStore recipients = m.getRecipientInfos();
    final RecipientInformation recipientInformation = recipients.get(recipientId);

    return SMIMEUtil.toMimeBodyPart(recipientInformation.getContent(recipient));
}
 
开发者ID:gini,项目名称:jersey-smime,代码行数:11,代码来源:EnvelopedTest.java


示例14: decrypt

import org.bouncycastle.mail.smime.SMIMEEnveloped; //导入依赖的package包/类
/**
 * Decrypts the encapsulated MIME body part.
 * 
 * @param privateKey the private key for decryption.
 * @return an S/MIME message encapsulating the decrypted MIME body part. 
 * @throws SMimeException if unable to decrpyt the body part.
 */
public SMimeMessage decrypt(PrivateKey privateKey) throws SMimeException {
    if (privateKey==null) {
        throw new SMimeException("Private key not found");
    }

    try {
        setDefaults();
 	    
        SMIMEEnveloped       m = new SMIMEEnveloped(bodyPart);

 // RecipientId          recId = new RecipientId();  // change to abstract class
 // 								   
 // recId.setSerialNumber(cert.getSerialNumber());		   
 // recId.setIssuer(cert.getIssuerX500Principal().getEncoded());
 
 RecipientId          recId = new JceKeyTransRecipientId(cert);

 // RecipientId          recId = new RecipientId();		   
 // 								   
        // recId.setSerialNumber(cert.getSerialNumber());		   
        // recId.setIssuer(cert.getIssuerX500Principal().getEncoded());

 // RecipientInformationStore  recipients = m.getRecipientInfos();
 // RecipientInformation       recipient = recipientsInfo.get(recId);
 
 RecipientInformationStore  recipientsInfo = m.getRecipientInfos();	
 RecipientInformation       recipientInfo = recipientsInfo.get(recId);

 if (recipientInfo == null) {				      
     throw new SMimeException("Invalid encrypted content");
 }
 
 JceKeyTransEnvelopedRecipient       recipient = new JceKeyTransEnvelopedRecipient(privateKey);
 recipient.setProvider(SECURITY_PROVIDER);							
 
        // ByteArrayInputStream ins = new ByteArrayInputStream(recipient.getContent(privateKey, "BC")); // Deprecated
 ByteArrayInputStream ins = new ByteArrayInputStream(recipientInfo.getContent(recipient));
        MimeBodyPart decryptedPart = new MimeBodyPart(ins); 
        return new SMimeMessage(decryptedPart, this);
    }
    catch (Exception e) {
        throw new SMimeException("Unable to decrypt body part", e);
    }
}
 
开发者ID:cecid,项目名称:hermes,代码行数:52,代码来源:SMimeMessage.java


示例15: testEncrytedAS2Message

import org.bouncycastle.mail.smime.SMIMEEnveloped; //导入依赖的package包/类
@Test
public void testEncrytedAS2Message() throws Exception{
    InputStream ins = FIXTURE_LOADER.getResourceAsStream(MOCK_AS2_MSG);
    ByteArrayInputStream bIns = new ByteArrayInputStream(IOHandler.readBytes(ins));
    String mid = RANDOM.toString();
    
    partnershipDVO.setIsOutboundEncryptRequired(true);
    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 RecipientId();
    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));
       
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    IOHandler.pipe( decrpted.getDataHandler().getInputStream(), baos);
    byte[] decrptedBA = baos.toByteArray();
    byte[] originalBA = IOHandler.readBytes(FIXTURE_LOADER.getResourceAsStream(MOCK_AS2_MSG));
       
    Assert.assertTrue(Arrays.equals(decrptedBA, originalBA));
       
    //Assert the filename
    String filenameHdr = decrpted.getHeader("Content-Disposition")[0];
    Assert.assertEquals("Filename value lost in BodyPartHeader",
			MOCK_AS2_MSG, getFileName(filenameHdr));

    //Verify MIC
    ByteArrayOutputStream contentStream = new ByteArrayOutputStream();
    decrpted.writeTo(contentStream);
    byte[] content = (contentStream.toByteArray());
    String mic = calculateMIC(content);
    Assert.assertEquals( "MIC Value is not valid.", mic, getStoredMessage(mid).getMicValue());
}
 
开发者ID:cecid,项目名称:hermes,代码行数:50,代码来源:OutgoingMessageProcessorTest.java


示例16: testSignedEncryptedAS2Message

import org.bouncycastle.mail.smime.SMIMEEnveloped; //导入依赖的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


示例17: main

import org.bouncycastle.mail.smime.SMIMEEnveloped; //导入依赖的package包/类
public static void main(
    String args[])
    throws Exception
{
    if (args.length != 2)
    {
        System.err.println("usage: ReadEncryptedMail pkcs12Keystore password");
        System.exit(0);
    }

    //
    // Open the key store
    //
    KeyStore    ks = KeyStore.getInstance("PKCS12", "BC");

    ks.load(new FileInputStream(args[0]), args[1].toCharArray());

    Enumeration e = ks.aliases();
    String      keyAlias = null;

    while (e.hasMoreElements())
    {
        String  alias = (String)e.nextElement();

        if (ks.isKeyEntry(alias))
        {
            keyAlias = alias;
        }
    }

    if (keyAlias == null)
    {
        System.err.println("can't find a private key!");
        System.exit(0);
    }

    //
    // find the certificate for the private key and generate a 
    // suitable recipient identifier.
    //
    X509Certificate cert = (X509Certificate)ks.getCertificate(keyAlias);
    RecipientId     recId = new JceKeyTransRecipientId(cert);

    //
    // Get a Session object with the default properties.
    //         
    Properties props = System.getProperties();

    Session session = Session.getDefaultInstance(props, null);

    MimeMessage msg = new MimeMessage(session, new FileInputStream("encrypted.message"));

    SMIMEEnveloped       m = new SMIMEEnveloped(msg);

    RecipientInformationStore   recipients = m.getRecipientInfos();
    RecipientInformation        recipient = recipients.get(recId);

    MimeBodyPart        res = SMIMEUtil.toMimeBodyPart(recipient.getContent(new JceKeyTransEnvelopedRecipient((PrivateKey)ks.getKey(keyAlias, null)).setProvider("BC")));

    System.out.println("Message Contents");
    System.out.println("----------------");
    System.out.println(res.getContent());
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:64,代码来源:ReadEncryptedMail.java


示例18: testAES128

import org.bouncycastle.mail.smime.SMIMEEnveloped; //导入依赖的package包/类
public void testAES128()
    throws Exception
{
    MimeMessage message = loadMessage("test128.message");

    SMIMEEnveloped env = new SMIMEEnveloped(message);

    RecipientInformationStore store = env.getRecipientInfos();

    RecipientInformation recipInfo = store.get(new JceKeyTransRecipientId(loadCert("cert.pem")));

    assertNotNull(recipInfo);

    byte[] content = recipInfo.getContent(new JceKeyTransEnvelopedRecipient(loadKey("key.pem")));

    assertTrue(org.bouncycastle.util.Arrays.areEqual(testMessage, content));
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:18,代码来源:NewSMIMEEnvelopedTest.java


示例19: testAES192

import org.bouncycastle.mail.smime.SMIMEEnveloped; //导入依赖的package包/类
public void testAES192()
    throws Exception
{
    MimeMessage message = loadMessage("test192.message");

    SMIMEEnveloped env = new SMIMEEnveloped(message);

    RecipientInformationStore store = env.getRecipientInfos();

    RecipientInformation recipInfo = store.get(new JceKeyTransRecipientId(loadCert("cert.pem")));

    assertNotNull(recipInfo);

    byte[] content = recipInfo.getContent(new JceKeyTransEnvelopedRecipient(loadKey("key.pem")));

    assertTrue(org.bouncycastle.util.Arrays.areEqual(testMessage, content));
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:18,代码来源:NewSMIMEEnvelopedTest.java


示例20: testAES256

import org.bouncycastle.mail.smime.SMIMEEnveloped; //导入依赖的package包/类
public void testAES256()
    throws Exception
{
    MimeMessage message = loadMessage("test256.message");

    SMIMEEnveloped env = new SMIMEEnveloped(message);

    RecipientInformationStore store = env.getRecipientInfos();

    RecipientInformation recipInfo = store.get(new JceKeyTransRecipientId(loadCert("cert.pem")));

    assertNotNull(recipInfo);

    byte[] content = recipInfo.getContent(new JceKeyTransEnvelopedRecipient(loadKey("key.pem")));

    assertTrue(org.bouncycastle.util.Arrays.areEqual(testMessage, content));
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:18,代码来源:NewSMIMEEnvelopedTest.java



注:本文中的org.bouncycastle.mail.smime.SMIMEEnveloped类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CElementInfo类代码示例发布时间:2022-05-23
下一篇:
Java PdfArray类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap