本文整理汇总了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);
}
}
示例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));
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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));
}
示例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));
}
示例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);
}
示例11: getRecipientId
import org.bouncycastle.cms.RecipientId; //导入依赖的package包/类
private RecipientId getRecipientId(
X509Certificate cert)
throws IOException, CertificateEncodingException
{
RecipientId recId = new JceKeyTransRecipientId(cert);
return recId;
}
示例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);
}
示例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));
}
示例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());
}
示例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);
}
}