当前位置: 首页>>代码示例>>Java>>正文


Java RecipientId类代码示例

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


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


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