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

Java RecipientId类代码示例

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

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



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

示例1: decrypt

import org.bouncycastle.cms.RecipientId; //导入依赖的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.cms.RecipientId; //导入依赖的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: decryptEnvelope

import org.bouncycastle.cms.RecipientId; //导入依赖的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


示例4: verifyAlgorithm

import org.bouncycastle.cms.RecipientId; //导入依赖的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


示例5: verifyParserAlgorithm

import org.bouncycastle.cms.RecipientId; //导入依赖的package包/类
private void verifyParserAlgorithm(
    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");
    SMIMEEnvelopedParser m = new SMIMEEnvelopedParser(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: verifyAlgorithm

import org.bouncycastle.cms.RecipientId; //导入依赖的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


示例7: verifyParserAlgorithm

import org.bouncycastle.cms.RecipientId; //导入依赖的package包/类
private void verifyParserAlgorithm(
    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());
    SMIMEEnvelopedParser m = new SMIMEEnvelopedParser(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: confirmDataReceived

import org.bouncycastle.cms.RecipientId; //导入依赖的package包/类
private static void confirmDataReceived(RecipientInformationStore recipients,
    byte[] expectedData, X509Certificate reciCert, PrivateKey reciPrivKey, String provider)
    throws CMSException, NoSuchProviderException, CertificateEncodingException, IOException
{
    RecipientId rid = new JceKeyAgreeRecipientId(reciCert);

    RecipientInformation recipient = recipients.get(rid);
    assertNotNull(recipient);

    byte[] actualData = recipient.getContent(reciPrivKey, provider);
    assertEquals(true, Arrays.equals(expectedData, actualData));
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:13,代码来源:EnvelopedDataTest.java


示例9: confirmDataReceived

import org.bouncycastle.cms.RecipientId; //导入依赖的package包/类
private static void confirmDataReceived(RecipientInformationStore recipients,
    byte[] expectedData, X509Certificate reciCert, PrivateKey reciPrivKey, String provider)
    throws CMSException, NoSuchProviderException, CertificateEncodingException, IOException
{
    RecipientId rid = new JceKeyAgreeRecipientId(reciCert);

    RecipientInformation recipient = recipients.get(rid);
    assertNotNull(recipient);

    byte[] actualData = recipient.getContent(new JceKeyAgreeEnvelopedRecipient(reciPrivKey).setProvider(provider));
    assertEquals(true, Arrays.equals(expectedData, actualData));
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:13,代码来源:NewEnvelopedDataTest.java


示例10: testCapEncrypt

import org.bouncycastle.cms.RecipientId; //导入依赖的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


示例11: getRecipientId

import org.bouncycastle.cms.RecipientId; //导入依赖的package包/类
private RecipientId getRecipientId(
    X509Certificate cert) 
    throws IOException, CertificateEncodingException
{
    RecipientId          recId = new JceKeyTransRecipientId(cert);

    return recId;
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:9,代码来源:SMIMEEnvelopedTest.java


示例12: testCapEncrypt

import org.bouncycastle.cms.RecipientId; //导入依赖的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.cms.RecipientId; //导入依赖的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: getRecipientId

import org.bouncycastle.cms.RecipientId; //导入依赖的package包/类
/**
 * Return a RecipientId for the identity's (private key, certificate) pair.
 */
public RecipientId getRecipientId()
{
    // TODO: handle key agreement
    return new KeyTransRecipientId(certificateHolders[0].getIssuer(), certificateHolders[0].getSerialNumber(), getSubjectKeyIdentifier());
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:9,代码来源:PKIXIdentity.java


示例15: decrypt

import org.bouncycastle.cms.RecipientId; //导入依赖的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


示例16: testEncrytedAS2Message

import org.bouncycastle.cms.RecipientId; //导入依赖的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


示例17: testSignedEncryptedAS2Message

import org.bouncycastle.cms.RecipientId; //导入依赖的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


示例18: addDecryptionSettings

import org.bouncycastle.cms.RecipientId; //导入依赖的package包/类
private void addDecryptionSettings() throws Exception {
    char[] smimePw = new String(decryptionKeystorePass).toCharArray();

    Security.addProvider(new BouncyCastleProvider());
    ks = KeyStore.getInstance(PKCS_KEYSTORE_TYPE, BOUNCY_CASTLE_PROVIDER);

    InputStream decryptionStream  = new URL(decryptionKeystore).openStream();
    try {
        ks.load(decryptionStream, smimePw);
    } finally {
        decryptionStream.close();
    }

    if ("".equals(decryptionKeyAlias)) {
        Enumeration aliases = ks.aliases();
        while (aliases.hasMoreElements()) {
            String alias = (String) aliases.nextElement();

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

        if ("".equals(decryptionKeyAlias)) {
            throw new Exception("Can't find a private key!");
        }
    }

    //
    // find the certificate for the private key and generate a
    // suitable recipient identifier.
    //
    X509Certificate cert = (X509Certificate)ks.getCertificate(decryptionKeyAlias);
    if (null == cert) {
        throw new Exception("Can't find a key pair with alias \"" + decryptionKeyAlias +
                "\" in the given keystore");
    }
    if (verifyCertificate) {
        cert.checkValidity();
    }

    recId = new RecipientId();
    recId.setSerialNumber(cert.getSerialNumber());
    recId.setIssuer(cert.getIssuerX500Principal().getEncoded());
}
 
开发者ID:CloudSlang,项目名称:cs-actions,代码行数:46,代码来源:GetMailMessage.java


示例19: main

import org.bouncycastle.cms.RecipientId; //导入依赖的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


示例20: main

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

    //
    // Open the key store
    //
    KeyStore    ks = KeyStore.getInstance("PKCS12", "BC");
    String      keyAlias = ExampleUtils.findKeyAlias(ks, args[0], args[1].toCharArray());

    //
    // 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 SharedFileInputStream("encrypted.message"));

    SMIMEEnvelopedParser       m = new SMIMEEnvelopedParser(msg);

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

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

    ExampleUtils.dumpContent(res, args[2]);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:42,代码来源:ReadLargeEncryptedMail.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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