本文整理汇总了Java中org.bouncycastle.cms.RecipientInformation.getContent方法的典型用法代码示例。如果您正苦于以下问题:Java RecipientInformation.getContent方法的具体用法?Java RecipientInformation.getContent怎么用?Java RecipientInformation.getContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.cms.RecipientInformation
的用法示例。
在下文中一共展示了RecipientInformation.getContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decrypt
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的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: testKeyTransLight128RC4
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的package包/类
private void testKeyTransLight128RC4()
throws Exception
{
byte[] data = "WallaWallaBouncyCastle".getBytes();
CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();
edGen.addRecipientInfoGenerator(new BcRSAKeyTransRecipientInfoGenerator(_reciCert));
CMSEnvelopedData ed = edGen.generate(
new CMSProcessableByteArray(data),
new BcCMSContentEncryptorBuilder(NISTObjectIdentifiers.id_aes128_CBC).build());
RecipientInformationStore recipients = ed.getRecipientInfos();
if (!ed.getEncryptionAlgOID().equals(NISTObjectIdentifiers.id_aes128_CBC.getId()))
{
fail("enc oid mismatch");
}
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
if (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
byte[] recData = recipient.getContent(new BcRSAKeyTransEnvelopedRecipient((AsymmetricKeyParameter)_reciKP.getPrivate()));
if (!Arrays.areEqual(data, recData))
{
fail("decryption failed");
}
}
else
{
fail("no recipient found");
}
}
示例3: testKeyTransLight128RC4
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的package包/类
public void testKeyTransLight128RC4()
throws Exception
{
byte[] data = "WallaWallaBouncyCastle".getBytes();
CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();
edGen.addRecipientInfoGenerator(new BcRSAKeyTransRecipientInfoGenerator(new JcaX509CertificateHolder(_reciCert)));
CMSEnvelopedData ed = edGen.generate(
new CMSProcessableByteArray(data),
new JceCMSContentEncryptorBuilder(new ASN1ObjectIdentifier("1.2.840.113549.3.4"), 128).setProvider(BC).build());
RecipientInformationStore recipients = ed.getRecipientInfos();
assertEquals(ed.getEncryptionAlgOID(), "1.2.840.113549.3.4");
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
if (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
byte[] recData = recipient.getContent(new JceKeyTransEnvelopedRecipient(_reciKP.getPrivate()).setProvider(BC));
assertEquals(true, Arrays.equals(data, recData));
}
else
{
fail("no recipient found");
}
}
示例4: testRFC4134ex5_2
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的package包/类
public void testRFC4134ex5_2()
throws Exception
{
byte[] data = Hex.decode("5468697320697320736f6d652073616d706c6520636f6e74656e742e");
KeyFactory kFact = KeyFactory.getInstance("RSA", BC);
PrivateKey key = kFact.generatePrivate(new PKCS8EncodedKeySpec(bobPrivRsaEncrypt));
CMSEnvelopedData ed = new CMSEnvelopedData(rfc4134ex5_2);
RecipientInformationStore recipients = ed.getRecipientInfos();
assertEquals("1.2.840.113549.3.2", ed.getEncryptionAlgOID());
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
if (it.hasNext())
{
while (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
byte[] recData;
if (recipient instanceof KeyTransRecipientInformation)
{
recData = recipient.getContent(new JceKeyTransEnvelopedRecipient(key).setProvider(BC));
assertEquals(true, Arrays.equals(data, recData));
}
}
}
else
{
fail("no recipient found");
}
}
示例5: testECKeyAgree
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的package包/类
public void testECKeyAgree()
throws Exception
{
byte[] data = Hex.decode("504b492d4320434d5320456e76656c6f706564446174612053616d706c65");
CMSAuthenticatedDataGenerator adGen = new CMSAuthenticatedDataGenerator();
adGen.addKeyAgreementRecipient(CMSAuthenticatedDataGenerator.ECDH_SHA1KDF, _origEcKP.getPrivate(), _origEcKP.getPublic(), _reciEcCert, CMSAuthenticatedDataGenerator.AES128_WRAP, BC);
CMSAuthenticatedData ad = adGen.generate(
new CMSProcessableByteArray(data),
CMSAuthenticatedDataGenerator.DES_EDE3_CBC, BC);
RecipientInformationStore recipients = ad.getRecipientInfos();
assertEquals(ad.getMacAlgOID(),
CMSAuthenticatedDataGenerator.DES_EDE3_CBC);
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
if (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
byte[] recData = recipient.getContent(_reciEcKP.getPrivate(), BC);
assertTrue(Arrays.equals(data, recData));
assertTrue(Arrays.equals(ad.getMac(), recipient.getMac()));
}
else
{
fail("no recipient found");
}
}
示例6: tryKekAlgorithm
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的package包/类
private void tryKekAlgorithm(SecretKey kek, DERObjectIdentifier algOid)
throws NoSuchAlgorithmException, NoSuchProviderException, CMSException
{
byte[] data = "Eric H. Echidna".getBytes();
CMSAuthenticatedDataGenerator adGen = new CMSAuthenticatedDataGenerator();
byte[] kekId = new byte[] { 1, 2, 3, 4, 5 };
adGen.addKEKRecipient(kek, kekId);
CMSAuthenticatedData ad = adGen.generate(
new CMSProcessableByteArray(data),
CMSAuthenticatedDataGenerator.DES_EDE3_CBC, BC);
RecipientInformationStore recipients = ad.getRecipientInfos();
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
assertEquals(ad.getMacAlgOID(), CMSAuthenticatedDataGenerator.DES_EDE3_CBC);
if (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
assertEquals(recipient.getKeyEncryptionAlgOID(), algOid.getId());
byte[] recData = recipient.getContent(kek, BC);
assertTrue(Arrays.equals(data, recData));
assertTrue(Arrays.equals(ad.getMac(), recipient.getMac()));
}
else
{
fail("no recipient found");
}
}
示例7: testErrorneousKEK
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的package包/类
public void testErrorneousKEK()
throws Exception
{
byte[] data = "WallaWallaWashington".getBytes();
SecretKey kek = new SecretKeySpec(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }, "AES");
CMSEnvelopedData ed = new CMSEnvelopedData(oldKEK);
RecipientInformationStore recipients = ed.getRecipientInfos();
assertEquals(ed.getEncryptionAlgOID(), CMSEnvelopedDataGenerator.DES_EDE3_CBC);
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
if (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
assertEquals(recipient.getKeyEncryptionAlgOID(), NISTObjectIdentifiers.id_aes128_wrap.getId());
byte[] recData = recipient.getContent(kek, BC);
assertEquals(true, Arrays.equals(data, recData));
}
else
{
fail("no recipient found");
}
}
示例8: testRFC4134ex5_2
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的package包/类
public void testRFC4134ex5_2()
throws Exception
{
byte[] data = Hex.decode("5468697320697320736f6d652073616d706c6520636f6e74656e742e");
KeyFactory kFact = KeyFactory.getInstance("RSA", BC);
PrivateKey key = kFact.generatePrivate(new PKCS8EncodedKeySpec(bobPrivRsaEncrypt));
CMSEnvelopedData ed = new CMSEnvelopedData(rfc4134ex5_2);
RecipientInformationStore recipients = ed.getRecipientInfos();
assertEquals("1.2.840.113549.3.2", ed.getEncryptionAlgOID());
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
if (it.hasNext())
{
while (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
byte[] recData;
if (recipient instanceof KeyTransRecipientInformation)
{
recData = recipient.getContent(new BcRSAKeyTransEnvelopedRecipient(PrivateKeyFactory.createKey(PrivateKeyInfo.getInstance(key.getEncoded()))));
assertEquals(true, Arrays.equals(data, recData));
}
}
}
else
{
fail("no recipient found");
}
}
示例9: testKeyTransSmallAES
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的package包/类
public void testKeyTransSmallAES()
throws Exception
{
byte[] data = new byte[] { 0, 1, 2, 3 };
CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();
edGen.addRecipientInfoGenerator(new BcRSAKeyTransRecipientInfoGenerator(new JcaX509CertificateHolder(_reciCert)));
CMSEnvelopedData ed = edGen.generate(
new CMSProcessableByteArray(data),
new BcCMSContentEncryptorBuilder(CMSAlgorithm.AES128_CBC).build());
RecipientInformationStore recipients = ed.getRecipientInfos();
assertEquals(ed.getEncryptionAlgOID(),
CMSAlgorithm.AES128_CBC.getId());
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
if (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
byte[] recData = recipient.getContent(new BcRSAKeyTransEnvelopedRecipient(PrivateKeyFactory.createKey(PrivateKeyInfo.getInstance(_reciKP.getPrivate().getEncoded()))));
assertEquals(true, Arrays.equals(data, recData));
}
else
{
fail("no recipient found");
}
}
示例10: testKeyTrans128RC4
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的package包/类
public void testKeyTrans128RC4()
throws Exception
{
byte[] data = "WallaWallaBouncyCastle".getBytes();
CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();
edGen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(_reciCert).setProvider(BC));
CMSEnvelopedData ed = edGen.generate(
new CMSProcessableByteArray(data),
new JceCMSContentEncryptorBuilder(new ASN1ObjectIdentifier("1.2.840.113549.3.4"), 128).setProvider(BC).build());
RecipientInformationStore recipients = ed.getRecipientInfos();
assertEquals(ed.getEncryptionAlgOID(), "1.2.840.113549.3.4");
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
if (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
byte[] recData = recipient.getContent(new JceKeyTransEnvelopedRecipient(_reciKP.getPrivate()).setProvider(BC));
assertEquals(true, Arrays.equals(data, recData));
}
else
{
fail("no recipient found");
}
}
示例11: testRFC4134ex5_1
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的package包/类
public void testRFC4134ex5_1()
throws Exception
{
byte[] data = Hex.decode("5468697320697320736f6d652073616d706c6520636f6e74656e742e");
KeyFactory kFact = KeyFactory.getInstance("RSA", BC);
Key key = kFact.generatePrivate(new PKCS8EncodedKeySpec(bobPrivRsaEncrypt));
CMSEnvelopedData ed = new CMSEnvelopedData(rfc4134ex5_1);
RecipientInformationStore recipients = ed.getRecipientInfos();
assertEquals("1.2.840.113549.3.7", ed.getEncryptionAlgOID());
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
if (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
byte[] recData = recipient.getContent(new BcRSAKeyTransEnvelopedRecipient(PrivateKeyFactory.createKey(PrivateKeyInfo.getInstance(key.getEncoded()))));
assertEquals(true, Arrays.equals(data, recData));
}
else
{
fail("no recipient found");
}
}
示例12: verifyECKeyAgreeVectors
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的package包/类
private void verifyECKeyAgreeVectors(PrivateKey privKey, String wrapAlg, byte[] message)
throws CMSException, GeneralSecurityException
{
byte[] data = Hex.decode("504b492d4320434d5320456e76656c6f706564446174612053616d706c65");
CMSEnvelopedData ed = new CMSEnvelopedData(message);
RecipientInformationStore recipients = ed.getRecipientInfos();
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
assertEquals(wrapAlg, ed.getEncryptionAlgOID());
if (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
assertEquals("1.3.133.16.840.63.0.2", recipient.getKeyEncryptionAlgOID());
byte[] recData = recipient.getContent(privKey, "BC");
assertTrue(Arrays.equals(data, recData));
}
else
{
fail("no recipient found");
}
}
示例13: tryKekAlgorithm
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的package包/类
private void tryKekAlgorithm(SecretKey kek, DERObjectIdentifier algOid)
throws NoSuchAlgorithmException, NoSuchProviderException, CMSException
{
byte[] data = "WallaWallaWashington".getBytes();
CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();
byte[] kekId = new byte[] { 1, 2, 3, 4, 5 };
edGen.addRecipientInfoGenerator(new JceKEKRecipientInfoGenerator(kekId, kek).setProvider(BC));
CMSEnvelopedData ed = edGen.generate(
new CMSProcessableByteArray(data),
new JceCMSContentEncryptorBuilder(CMSAlgorithm.DES_EDE3_CBC).setProvider(BC).build());
RecipientInformationStore recipients = ed.getRecipientInfos();
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
assertEquals(ed.getEncryptionAlgOID(), CMSEnvelopedDataGenerator.DES_EDE3_CBC);
if (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
assertEquals(algOid.getId(), recipient.getKeyEncryptionAlgOID());
byte[] recData = recipient.getContent(new JceKEKEnvelopedRecipient(kek).setProvider(BC));
assertTrue(Arrays.equals(data, recData));
}
else
{
fail("no recipient found");
}
}
示例14: testRFC4134ex5_2
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的package包/类
public void testRFC4134ex5_2()
throws Exception
{
byte[] data = Hex.decode("5468697320697320736f6d652073616d706c6520636f6e74656e742e");
KeyFactory kFact = KeyFactory.getInstance("RSA", "BC");
Key key = kFact.generatePrivate(new PKCS8EncodedKeySpec(bobPrivRsaEncrypt));
CMSEnvelopedData ed = new CMSEnvelopedData(rfc4134ex5_2);
RecipientInformationStore recipients = ed.getRecipientInfos();
assertEquals("1.2.840.113549.3.2", ed.getEncryptionAlgOID());
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
if (it.hasNext())
{
while (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
byte[] recData;
if (recipient instanceof KeyTransRecipientInformation)
{
recData = recipient.getContent(key, "BC");
assertEquals(true, Arrays.equals(data, recData));
}
}
}
else
{
fail("no recipient found");
}
}
示例15: decrypt
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的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);
}
}