本文整理汇总了Java中org.bouncycastle.cms.CMSEnvelopedDataStreamGenerator.open方法的典型用法代码示例。如果您正苦于以下问题:Java CMSEnvelopedDataStreamGenerator.open方法的具体用法?Java CMSEnvelopedDataStreamGenerator.open怎么用?Java CMSEnvelopedDataStreamGenerator.open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.cms.CMSEnvelopedDataStreamGenerator
的用法示例。
在下文中一共展示了CMSEnvelopedDataStreamGenerator.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testKeyTransAES128Throughput
import org.bouncycastle.cms.CMSEnvelopedDataStreamGenerator; //导入方法依赖的package包/类
public void testKeyTransAES128Throughput()
throws Exception
{
byte[] data = new byte[40001];
for (int i = 0; i != data.length; i++)
{
data[i] = (byte)(i & 0xff);
}
//
// buffered
//
CMSEnvelopedDataStreamGenerator edGen = new CMSEnvelopedDataStreamGenerator();
edGen.setBufferSize(BUFFER_SIZE);
edGen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(_reciCert).setProvider(BC));
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
OutputStream out = edGen.open(bOut, new JceCMSContentEncryptorBuilder(CMSAlgorithm.AES128_CBC).setProvider(BC).build());
for (int i = 0; i != data.length; i++)
{
out.write(data[i]);
}
out.close();
CMSEnvelopedDataParser ep = new CMSEnvelopedDataParser(bOut.toByteArray());
RecipientInformationStore recipients = ep.getRecipientInfos();
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
if (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
assertEquals(recipient.getKeyEncryptionAlgOID(), PKCSObjectIdentifiers.rsaEncryption.getId());
CMSTypedStream recData = recipient.getContentStream(new JceKeyTransEnvelopedRecipient(_reciKP.getPrivate()).setProvider(BC));
InputStream dataStream = recData.getContentStream();
ByteArrayOutputStream dataOut = new ByteArrayOutputStream();
int len;
byte[] buf = new byte[BUFFER_SIZE];
int count = 0;
while (count != 10 && (len = dataStream.read(buf)) > 0)
{
assertEquals(buf.length, len);
dataOut.write(buf);
count++;
}
len = dataStream.read(buf);
dataOut.write(buf, 0, len);
assertEquals(true, Arrays.equals(data, dataOut.toByteArray()));
}
else
{
fail("recipient not found.");
}
}
示例2: testKeyTransAES128Throughput
import org.bouncycastle.cms.CMSEnvelopedDataStreamGenerator; //导入方法依赖的package包/类
public void testKeyTransAES128Throughput()
throws Exception
{
byte[] data = new byte[40001];
for (int i = 0; i != data.length; i++)
{
data[i] = (byte)(i & 0xff);
}
//
// buffered
//
CMSEnvelopedDataStreamGenerator edGen = new CMSEnvelopedDataStreamGenerator();
edGen.setBufferSize(BUFFER_SIZE);
edGen.addKeyTransRecipient(_reciCert);
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
OutputStream out = edGen.open(bOut, CMSEnvelopedDataGenerator.AES128_CBC, BC);
for (int i = 0; i != data.length; i++)
{
out.write(data[i]);
}
out.close();
CMSEnvelopedDataParser ep = new CMSEnvelopedDataParser(bOut.toByteArray());
RecipientInformationStore recipients = ep.getRecipientInfos();
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
if (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
assertEquals(recipient.getKeyEncryptionAlgOID(), PKCSObjectIdentifiers.rsaEncryption.getId());
CMSTypedStream recData = recipient.getContentStream(_reciKP.getPrivate(), BC);
InputStream dataStream = recData.getContentStream();
ByteArrayOutputStream dataOut = new ByteArrayOutputStream();
int len;
byte[] buf = new byte[BUFFER_SIZE];
int count = 0;
while (count != 10 && (len = dataStream.read(buf)) > 0)
{
assertEquals(buf.length, len);
dataOut.write(buf);
count++;
}
len = dataStream.read(buf);
dataOut.write(buf, 0, len);
assertEquals(true, Arrays.equals(data, dataOut.toByteArray()));
}
else
{
fail("recipient not found.");
}
}
示例3: testKeyTransAES128Der
import org.bouncycastle.cms.CMSEnvelopedDataStreamGenerator; //导入方法依赖的package包/类
public void testKeyTransAES128Der()
throws Exception
{
byte[] data = new byte[2000];
for (int i = 0; i != 2000; i++)
{
data[i] = (byte)(i & 0xff);
}
CMSEnvelopedDataStreamGenerator edGen = new CMSEnvelopedDataStreamGenerator();
edGen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(_reciCert).setProvider(BC));
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
OutputStream out = edGen.open(
bOut, new JceCMSContentEncryptorBuilder(CMSAlgorithm.AES128_CBC).setProvider(BC).build());
for (int i = 0; i != 2000; i++)
{
out.write(data[i]);
}
out.close();
// convert to DER
ASN1InputStream aIn = new ASN1InputStream(bOut.toByteArray());
bOut.reset();
DEROutputStream dOut = new DEROutputStream(bOut);
dOut.writeObject(aIn.readObject());
verifyData(bOut, CMSEnvelopedDataGenerator.AES128_CBC, data);
}
示例4: testKeyTransAES128
import org.bouncycastle.cms.CMSEnvelopedDataStreamGenerator; //导入方法依赖的package包/类
public void testKeyTransAES128()
throws Exception
{
byte[] data = "WallaWallaWashington".getBytes();
CMSEnvelopedDataStreamGenerator edGen = new CMSEnvelopedDataStreamGenerator();
edGen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(_reciCert).setProvider(BC));
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
OutputStream out = edGen.open(
bOut, new JceCMSContentEncryptorBuilder(CMSAlgorithm.AES128_CBC).setProvider(BC).build());
out.write(data);
out.close();
CMSEnvelopedDataParser ep = new CMSEnvelopedDataParser(bOut.toByteArray());
RecipientInformationStore recipients = ep.getRecipientInfos();
assertEquals(ep.getEncryptionAlgOID(), CMSEnvelopedDataGenerator.AES128_CBC);
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
while (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
assertEquals(recipient.getKeyEncryptionAlgOID(), PKCSObjectIdentifiers.rsaEncryption.getId());
CMSTypedStream recData = recipient.getContentStream(new JceKeyTransEnvelopedRecipient(_reciKP.getPrivate()).setProvider(BC));
assertEquals(true, Arrays.equals(data, CMSTestUtil.streamToByteArray(recData.getContentStream())));
}
ep.close();
}
示例5: testKeyTransAES128
import org.bouncycastle.cms.CMSEnvelopedDataStreamGenerator; //导入方法依赖的package包/类
public void testKeyTransAES128()
throws Exception
{
byte[] data = "WallaWallaWashington".getBytes();
CMSEnvelopedDataStreamGenerator edGen = new CMSEnvelopedDataStreamGenerator();
edGen.addKeyTransRecipient(_reciCert);
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
OutputStream out = edGen.open(
bOut, CMSEnvelopedDataGenerator.AES128_CBC, BC);
out.write(data);
out.close();
CMSEnvelopedDataParser ep = new CMSEnvelopedDataParser(bOut.toByteArray());
RecipientInformationStore recipients = ep.getRecipientInfos();
assertEquals(ep.getEncryptionAlgOID(), CMSEnvelopedDataGenerator.AES128_CBC);
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
while (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
assertEquals(recipient.getKeyEncryptionAlgOID(), PKCSObjectIdentifiers.rsaEncryption.getId());
CMSTypedStream recData = recipient.getContentStream(_reciKP.getPrivate(), BC);
assertEquals(true, Arrays.equals(data, CMSTestUtil.streamToByteArray(recData.getContentStream())));
}
ep.close();
}
示例6: testKeyTransAES128Der
import org.bouncycastle.cms.CMSEnvelopedDataStreamGenerator; //导入方法依赖的package包/类
public void testKeyTransAES128Der()
throws Exception
{
byte[] data = new byte[2000];
for (int i = 0; i != 2000; i++)
{
data[i] = (byte)(i & 0xff);
}
CMSEnvelopedDataStreamGenerator edGen = new CMSEnvelopedDataStreamGenerator();
edGen.addKeyTransRecipient(_reciCert);
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
OutputStream out = edGen.open(
bOut, CMSEnvelopedDataGenerator.AES128_CBC, BC);
for (int i = 0; i != 2000; i++)
{
out.write(data[i]);
}
out.close();
// convert to DER
ASN1InputStream aIn = new ASN1InputStream(bOut.toByteArray());
bOut.reset();
DEROutputStream dOut = new DEROutputStream(bOut);
dOut.writeObject(aIn.readObject());
verifyData(bOut, CMSEnvelopedDataGenerator.AES128_CBC, data);
}
示例7: testECKeyAgree
import org.bouncycastle.cms.CMSEnvelopedDataStreamGenerator; //导入方法依赖的package包/类
public void testECKeyAgree()
throws Exception
{
byte[] data = Hex.decode("504b492d4320434d5320456e76656c6f706564446174612053616d706c65");
CMSEnvelopedDataStreamGenerator edGen = new CMSEnvelopedDataStreamGenerator();
edGen.addKeyAgreementRecipient(CMSEnvelopedDataGenerator.ECDH_SHA1KDF, _origEcKP.getPrivate(), _origEcKP.getPublic(), _reciEcCert, CMSEnvelopedDataGenerator.AES128_WRAP, BC);
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
OutputStream out = edGen.open(
bOut,
CMSEnvelopedDataGenerator.AES128_CBC, BC);
out.write(data);
out.close();
CMSEnvelopedDataParser ep = new CMSEnvelopedDataParser(bOut.toByteArray());
RecipientInformationStore recipients = ep.getRecipientInfos();
assertEquals(ep.getEncryptionAlgOID(), CMSEnvelopedDataGenerator.AES128_CBC);
RecipientId recSel = new JceKeyAgreeRecipientId(_reciEcCert);
RecipientInformation recipient = recipients.get(recSel);
CMSTypedStream recData = recipient.getContentStream(_reciEcKP.getPrivate(), BC);
assertEquals(true, Arrays.equals(data, CMSTestUtil.streamToByteArray(recData.getContentStream())));
ep.close();
}
示例8: testAESKEK
import org.bouncycastle.cms.CMSEnvelopedDataStreamGenerator; //导入方法依赖的package包/类
public void testAESKEK()
throws Exception
{
byte[] data = "WallaWallaWashington".getBytes();
SecretKey kek = CMSTestUtil.makeAES192Key();
CMSEnvelopedDataStreamGenerator edGen = new CMSEnvelopedDataStreamGenerator();
byte[] kekId = new byte[] { 1, 2, 3, 4, 5 };
edGen.addKEKRecipient(kek, kekId);
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
OutputStream out = edGen.open(
bOut,
CMSEnvelopedDataGenerator.DES_EDE3_CBC, BC);
out.write(data);
out.close();
CMSEnvelopedDataParser ep = new CMSEnvelopedDataParser(bOut.toByteArray());
RecipientInformationStore recipients = ep.getRecipientInfos();
assertEquals(ep.getEncryptionAlgOID(), CMSEnvelopedDataGenerator.DES_EDE3_CBC);
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
while (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
assertEquals(recipient.getKeyEncryptionAlgOID(), "2.16.840.1.101.3.4.1.25");
CMSTypedStream recData = recipient.getContentStream(kek, BC);
assertEquals(true, Arrays.equals(data, CMSTestUtil.streamToByteArray(recData.getContentStream())));
}
ep.close();
}
示例9: testKeyTransAES128AndOriginatorInfo
import org.bouncycastle.cms.CMSEnvelopedDataStreamGenerator; //导入方法依赖的package包/类
public void testKeyTransAES128AndOriginatorInfo()
throws Exception
{
byte[] data = "WallaWallaWashington".getBytes();
CMSEnvelopedDataStreamGenerator edGen = new CMSEnvelopedDataStreamGenerator();
X509CertificateHolder origCert = new X509CertificateHolder(_origCert.getEncoded());
edGen.setOriginatorInfo(new OriginatorInfoGenerator(origCert).generate());
edGen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(_reciCert).setProvider(BC));
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
OutputStream out = edGen.open(
bOut, new JceCMSContentEncryptorBuilder(CMSAlgorithm.AES128_CBC).setProvider(BC).build());
out.write(data);
out.close();
CMSEnvelopedDataParser ep = new CMSEnvelopedDataParser(bOut.toByteArray());
assertTrue(ep.getOriginatorInfo().getCertificates().getMatches(null).contains(origCert));
RecipientInformationStore recipients = ep.getRecipientInfos();
assertEquals(ep.getEncryptionAlgOID(), CMSEnvelopedDataGenerator.AES128_CBC);
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
while (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
assertEquals(recipient.getKeyEncryptionAlgOID(), PKCSObjectIdentifiers.rsaEncryption.getId());
CMSTypedStream recData = recipient.getContentStream(new JceKeyTransEnvelopedRecipient(_reciKP.getPrivate()).setProvider(BC));
assertEquals(true, Arrays.equals(data, CMSTestUtil.streamToByteArray(recData.getContentStream())));
}
ep.close();
}
示例10: testAESKEK
import org.bouncycastle.cms.CMSEnvelopedDataStreamGenerator; //导入方法依赖的package包/类
public void testAESKEK()
throws Exception
{
byte[] data = "WallaWallaWashington".getBytes();
SecretKey kek = CMSTestUtil.makeAES192Key();
CMSEnvelopedDataStreamGenerator edGen = new CMSEnvelopedDataStreamGenerator();
byte[] kekId = new byte[] { 1, 2, 3, 4, 5 };
edGen.addRecipientInfoGenerator(new JceKEKRecipientInfoGenerator(kekId, kek).setProvider(BC));
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
OutputStream out = edGen.open(
bOut,
new JceCMSContentEncryptorBuilder(CMSAlgorithm.DES_EDE3_CBC).setProvider(BC).build());
out.write(data);
out.close();
CMSEnvelopedDataParser ep = new CMSEnvelopedDataParser(bOut.toByteArray());
RecipientInformationStore recipients = ep.getRecipientInfos();
assertEquals(ep.getEncryptionAlgOID(), CMSEnvelopedDataGenerator.DES_EDE3_CBC);
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
while (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
assertEquals(recipient.getKeyEncryptionAlgOID(), "2.16.840.1.101.3.4.1.25");
CMSTypedStream recData = recipient.getContentStream(new JceKEKEnvelopedRecipient(kek).setProvider(BC));
assertEquals(true, Arrays.equals(data, CMSTestUtil.streamToByteArray(recData.getContentStream())));
}
ep.close();
}
示例11: testTwoAESKEK
import org.bouncycastle.cms.CMSEnvelopedDataStreamGenerator; //导入方法依赖的package包/类
public void testTwoAESKEK()
throws Exception
{
byte[] data = "WallaWallaWashington".getBytes();
SecretKey kek1 = CMSTestUtil.makeAES192Key();
SecretKey kek2 = CMSTestUtil.makeAES192Key();
CMSEnvelopedDataStreamGenerator edGen = new CMSEnvelopedDataStreamGenerator();
byte[] kekId1 = new byte[] { 1, 2, 3, 4, 5 };
byte[] kekId2 = new byte[] { 5, 4, 3, 2, 1 };
edGen.addRecipientInfoGenerator(new JceKEKRecipientInfoGenerator(kekId1, kek1).setProvider(BC));
edGen.addRecipientInfoGenerator(new JceKEKRecipientInfoGenerator(kekId2, kek2).setProvider(BC));
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
OutputStream out = edGen.open(
bOut,
new JceCMSContentEncryptorBuilder(CMSAlgorithm.DES_EDE3_CBC).setProvider(BC).build());
out.write(data);
out.close();
CMSEnvelopedDataParser ep = new CMSEnvelopedDataParser(bOut.toByteArray());
RecipientInformationStore recipients = ep.getRecipientInfos();
assertEquals(ep.getEncryptionAlgOID(), CMSEnvelopedDataGenerator.DES_EDE3_CBC);
RecipientId recSel = new KEKRecipientId(kekId2);
RecipientInformation recipient = recipients.get(recSel);
assertEquals(recipient.getKeyEncryptionAlgOID(), "2.16.840.1.101.3.4.1.25");
CMSTypedStream recData = recipient.getContentStream(new JceKEKEnvelopedRecipient(kek2).setProvider(BC));
assertEquals(true, Arrays.equals(data, CMSTestUtil.streamToByteArray(recData.getContentStream())));
ep.close();
}
示例12: testKeyTransCAST5SunJCE
import org.bouncycastle.cms.CMSEnvelopedDataStreamGenerator; //导入方法依赖的package包/类
public void testKeyTransCAST5SunJCE()
throws Exception
{
if (Security.getProvider("SunJCE") == null)
{
return;
}
String version = System.getProperty("java.version");
if (version.startsWith("1.4") || version.startsWith("1.3"))
{
return;
}
byte[] data = "WallaWallaWashington".getBytes();
CMSEnvelopedDataStreamGenerator edGen = new CMSEnvelopedDataStreamGenerator();
edGen.addKeyTransRecipient(_reciCert);
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
OutputStream out = edGen.open(
bOut, CMSEnvelopedDataGenerator.CAST5_CBC, "SunJCE");
out.write(data);
out.close();
CMSEnvelopedDataParser ep = new CMSEnvelopedDataParser(bOut.toByteArray());
RecipientInformationStore recipients = ep.getRecipientInfos();
assertEquals(ep.getEncryptionAlgOID(), CMSEnvelopedDataGenerator.CAST5_CBC);
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
while (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
assertEquals(recipient.getKeyEncryptionAlgOID(), PKCSObjectIdentifiers.rsaEncryption.getId());
CMSTypedStream recData = recipient.getContentStream(_reciKP.getPrivate(), "SunJCE");
assertEquals(true, Arrays.equals(data, CMSTestUtil.streamToByteArray(recData.getContentStream())));
}
ep.close();
}
示例13: testTwoAESKEK
import org.bouncycastle.cms.CMSEnvelopedDataStreamGenerator; //导入方法依赖的package包/类
public void testTwoAESKEK()
throws Exception
{
byte[] data = "WallaWallaWashington".getBytes();
SecretKey kek1 = CMSTestUtil.makeAES192Key();
SecretKey kek2 = CMSTestUtil.makeAES192Key();
CMSEnvelopedDataStreamGenerator edGen = new CMSEnvelopedDataStreamGenerator();
byte[] kekId1 = new byte[] { 1, 2, 3, 4, 5 };
byte[] kekId2 = new byte[] { 5, 4, 3, 2, 1 };
edGen.addKEKRecipient(kek1, kekId1);
edGen.addKEKRecipient(kek2, kekId2);
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
OutputStream out = edGen.open(
bOut,
CMSEnvelopedDataGenerator.DES_EDE3_CBC, BC);
out.write(data);
out.close();
CMSEnvelopedDataParser ep = new CMSEnvelopedDataParser(bOut.toByteArray());
RecipientInformationStore recipients = ep.getRecipientInfos();
assertEquals(ep.getEncryptionAlgOID(), CMSEnvelopedDataGenerator.DES_EDE3_CBC);
RecipientId recSel = new KEKRecipientId(kekId2);
RecipientInformation recipient = recipients.get(recSel);
assertEquals(recipient.getKeyEncryptionAlgOID(), "2.16.840.1.101.3.4.1.25");
CMSTypedStream recData = recipient.getContentStream(kek2, BC);
assertEquals(true, Arrays.equals(data, CMSTestUtil.streamToByteArray(recData.getContentStream())));
ep.close();
}
示例14: testUnprotectedAttributes
import org.bouncycastle.cms.CMSEnvelopedDataStreamGenerator; //导入方法依赖的package包/类
public void testUnprotectedAttributes()
throws Exception
{
byte[] data = "WallaWallaWashington".getBytes();
CMSEnvelopedDataStreamGenerator edGen = new CMSEnvelopedDataStreamGenerator();
edGen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(_reciCert).setProvider(BC));
Hashtable attrs = new Hashtable();
attrs.put(PKCSObjectIdentifiers.id_aa_contentHint, new Attribute(PKCSObjectIdentifiers.id_aa_contentHint, new DERSet(new DERUTF8String("Hint"))));
attrs.put(PKCSObjectIdentifiers.id_aa_receiptRequest, new Attribute(PKCSObjectIdentifiers.id_aa_receiptRequest, new DERSet(new DERUTF8String("Request"))));
AttributeTable attrTable = new AttributeTable(attrs);
edGen.setUnprotectedAttributeGenerator(new SimpleAttributeTableGenerator(attrTable));
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
OutputStream out = edGen.open(
bOut, new JceCMSContentEncryptorBuilder(CMSAlgorithm.AES128_CBC).setProvider(BC).build());
out.write(data);
out.close();
CMSEnvelopedDataParser ed = new CMSEnvelopedDataParser(bOut.toByteArray());
RecipientInformationStore recipients = ed.getRecipientInfos();
Collection c = recipients.getRecipients();
assertEquals(1, c.size());
Iterator it = c.iterator();
while (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
assertEquals(recipient.getKeyEncryptionAlgOID(), PKCSObjectIdentifiers.rsaEncryption.getId());
byte[] recData = recipient.getContent(new JceKeyTransEnvelopedRecipient(_reciKP.getPrivate()).setProvider(BC));
assertEquals(true, Arrays.equals(data, recData));
}
attrTable = ed.getUnprotectedAttributes();
assertEquals(attrs.size(), 2);
assertEquals(new DERUTF8String("Hint"), attrTable.get(PKCSObjectIdentifiers.id_aa_contentHint).getAttrValues().getObjectAt(0));
assertEquals(new DERUTF8String("Request"), attrTable.get(PKCSObjectIdentifiers.id_aa_receiptRequest).getAttrValues().getObjectAt(0));
}
示例15: testKeyTransCAST5SunJCE
import org.bouncycastle.cms.CMSEnvelopedDataStreamGenerator; //导入方法依赖的package包/类
public void testKeyTransCAST5SunJCE()
throws Exception
{
if (Security.getProvider("SunJCE") == null)
{
return;
}
String version = System.getProperty("java.version");
if (version.startsWith("1.4") || version.startsWith("1.3"))
{
return;
}
byte[] data = "WallaWallaWashington".getBytes();
CMSEnvelopedDataStreamGenerator edGen = new CMSEnvelopedDataStreamGenerator();
edGen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(_reciCert).setProvider("SunJCE"));
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
OutputStream out = edGen.open(
bOut, new JceCMSContentEncryptorBuilder(CMSAlgorithm.CAST5_CBC).setProvider(BC).build());
out.write(data);
out.close();
CMSEnvelopedDataParser ep = new CMSEnvelopedDataParser(bOut.toByteArray());
RecipientInformationStore recipients = ep.getRecipientInfos();
assertEquals(ep.getEncryptionAlgOID(), CMSEnvelopedDataGenerator.CAST5_CBC);
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
while (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
assertEquals(recipient.getKeyEncryptionAlgOID(), PKCSObjectIdentifiers.rsaEncryption.getId());
CMSTypedStream recData = recipient.getContentStream(new JceKeyTransEnvelopedRecipient(_reciKP.getPrivate()).setProvider("SunJCE").setContentProvider(BC));
assertEquals(true, Arrays.equals(data, CMSTestUtil.streamToByteArray(recData.getContentStream())));
}
ep.close();
}