本文整理汇总了Java中org.bouncycastle.cms.RecipientInformation.getContentStream方法的典型用法代码示例。如果您正苦于以下问题:Java RecipientInformation.getContentStream方法的具体用法?Java RecipientInformation.getContentStream怎么用?Java RecipientInformation.getContentStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.cms.RecipientInformation
的用法示例。
在下文中一共展示了RecipientInformation.getContentStream方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyData
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的package包/类
private void verifyData(
ByteArrayOutputStream encodedStream,
String expectedOid,
byte[] expectedData)
throws Exception
{
CMSEnvelopedDataParser ep = new CMSEnvelopedDataParser(encodedStream.toByteArray());
RecipientInformationStore recipients = ep.getRecipientInfos();
assertEquals(ep.getEncryptionAlgOID(), expectedOid);
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(expectedData, CMSTestUtil.streamToByteArray(recData.getContentStream())));
}
}
示例2: verifyData
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的package包/类
private void verifyData(
ByteArrayOutputStream encodedStream,
String expectedOid,
byte[] expectedData)
throws Exception
{
CMSEnvelopedDataParser ep = new CMSEnvelopedDataParser(encodedStream.toByteArray());
RecipientInformationStore recipients = ep.getRecipientInfos();
assertEquals(ep.getEncryptionAlgOID(), expectedOid);
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(expectedData, CMSTestUtil.streamToByteArray(recData.getContentStream())));
}
}
示例3: testWorkingData
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的package包/类
public void testWorkingData()
throws Exception
{
byte[] keyData = Base64.decode(
"MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKrAz/SQKrcQ" +
"nj9IxHIfKDbuXsMqUpI06s2gps6fp7RDNvtUDDMOciWGFhD45YSy8GO0mPx3" +
"Nkc7vKBqX4TLcqLUz7kXGOHGOwiPZoNF+9jBMPNROe/B0My0PkWg9tuq+nxN" +
"64oD47+JvDwrpNOS5wsYavXeAW8Anv9ZzHLU7KwZAgMBAAECgYA/fqdVt+5K" +
"WKGfwr1Z+oAHvSf7xtchiw/tGtosZ24DOCNP3fcTXUHQ9kVqVkNyzt9ZFCT3" +
"bJUAdBQ2SpfuV4DusVeQZVzcROKeA09nPkxBpTefWbSDQGhb+eZq9L8JDRSW" +
"HyYqs+MBoUpLw7GKtZiJkZyY6CsYkAnQ+uYVWq/TIQJBAP5zafO4HUV/w4KD" +
"VJi+ua+GYF1Sg1t/dYL1kXO9GP1p75YAmtm6LdnOCas7wj70/G1YlPGkOP0V" +
"GFzeG5KAmAUCQQCryvKU9nwWA+kypcQT9Yr1P4vGS0APYoBThnZq7jEPc5Cm" +
"ZI82yseSxSeea0+8KQbZ5mvh1p3qImDLEH/iNSQFAkAghS+tboKPN10NeSt+" +
"uiGRRWNbiggv0YJ7Uldcq3ZeLQPp7/naiekCRUsHD4Qr97OrZf7jQ1HlRqTu" +
"eZScjMLhAkBNUMZCQnhwFAyEzdPkQ7LpU1MdyEopYmRssuxijZao5JLqQAGw" +
"YCzXokGFa7hz72b09F4DQurJL/WuDlvvu4jdAkEAxwT9lylvfSfEQw4/qQgZ" +
"MFB26gqB6Gqs1pHIZCzdliKx5BO3VDeUGfXMI8yOkbXoWbYx5xPid/+N8R//" +
"+sxLBw==");
byte[] envData = Base64.decode(
"MIAGCSqGSIb3DQEHA6CAMIACAQAxgcQwgcECAQAwKjAlMRYwFAYDVQQKEw1C" +
"b3VuY3kgQ2FzdGxlMQswCQYDVQQGEwJBVQIBHjANBgkqhkiG9w0BAQEFAASB" +
"gDmnaDZ0vDJNlaUSYyEXsgbaUH+itNTjCOgv77QTX2ImXj+kTctM19PQF2I1" +
"0/NL0fjakvCgBTHKmk13a7jqB6cX3bysenHNrglHsgNGgeXQ7ggAq5fV/JQQ" +
"T7rSxEtuwpbuHQnoVUZahOHVKy/a0uLr9iIh1A3y+yZTZaG505ZJMIAGCSqG" +
"SIb3DQEHATAdBglghkgBZQMEAQIEENmkYNbDXiZxJWtq82qIRZKggAQgkOGr" +
"1JcTsADStez1eY4+rO4DtyBIyUYQ3pilnbirfPkAAAAAAAAAAAAA");
CMSEnvelopedDataParser ep = new CMSEnvelopedDataParser(envData);
RecipientInformationStore recipients = ep.getRecipientInfos();
assertEquals(ep.getEncryptionAlgOID(), CMSEnvelopedDataGenerator.AES128_CBC);
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyData);
KeyFactory keyFact = KeyFactory.getInstance("RSA", BC);
Key priKey = keyFact.generatePrivate(keySpec);
byte[] data = Hex.decode("57616c6c6157616c6c6157617368696e67746f6e");
while (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
assertEquals(recipient.getKeyEncryptionAlgOID(), PKCSObjectIdentifiers.rsaEncryption.getId());
CMSTypedStream recData = recipient.getContentStream(priKey, BC);
assertEquals(true, Arrays.equals(data, CMSTestUtil.streamToByteArray(recData.getContentStream())));
}
}
示例4: testWorkingData
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的package包/类
public void testWorkingData()
throws Exception
{
byte[] keyData = Base64.decode(
"MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKrAz/SQKrcQ" +
"nj9IxHIfKDbuXsMqUpI06s2gps6fp7RDNvtUDDMOciWGFhD45YSy8GO0mPx3" +
"Nkc7vKBqX4TLcqLUz7kXGOHGOwiPZoNF+9jBMPNROe/B0My0PkWg9tuq+nxN" +
"64oD47+JvDwrpNOS5wsYavXeAW8Anv9ZzHLU7KwZAgMBAAECgYA/fqdVt+5K" +
"WKGfwr1Z+oAHvSf7xtchiw/tGtosZ24DOCNP3fcTXUHQ9kVqVkNyzt9ZFCT3" +
"bJUAdBQ2SpfuV4DusVeQZVzcROKeA09nPkxBpTefWbSDQGhb+eZq9L8JDRSW" +
"HyYqs+MBoUpLw7GKtZiJkZyY6CsYkAnQ+uYVWq/TIQJBAP5zafO4HUV/w4KD" +
"VJi+ua+GYF1Sg1t/dYL1kXO9GP1p75YAmtm6LdnOCas7wj70/G1YlPGkOP0V" +
"GFzeG5KAmAUCQQCryvKU9nwWA+kypcQT9Yr1P4vGS0APYoBThnZq7jEPc5Cm" +
"ZI82yseSxSeea0+8KQbZ5mvh1p3qImDLEH/iNSQFAkAghS+tboKPN10NeSt+" +
"uiGRRWNbiggv0YJ7Uldcq3ZeLQPp7/naiekCRUsHD4Qr97OrZf7jQ1HlRqTu" +
"eZScjMLhAkBNUMZCQnhwFAyEzdPkQ7LpU1MdyEopYmRssuxijZao5JLqQAGw" +
"YCzXokGFa7hz72b09F4DQurJL/WuDlvvu4jdAkEAxwT9lylvfSfEQw4/qQgZ" +
"MFB26gqB6Gqs1pHIZCzdliKx5BO3VDeUGfXMI8yOkbXoWbYx5xPid/+N8R//" +
"+sxLBw==");
byte[] envData = Base64.decode(
"MIAGCSqGSIb3DQEHA6CAMIACAQAxgcQwgcECAQAwKjAlMRYwFAYDVQQKEw1C" +
"b3VuY3kgQ2FzdGxlMQswCQYDVQQGEwJBVQIBHjANBgkqhkiG9w0BAQEFAASB" +
"gDmnaDZ0vDJNlaUSYyEXsgbaUH+itNTjCOgv77QTX2ImXj+kTctM19PQF2I1" +
"0/NL0fjakvCgBTHKmk13a7jqB6cX3bysenHNrglHsgNGgeXQ7ggAq5fV/JQQ" +
"T7rSxEtuwpbuHQnoVUZahOHVKy/a0uLr9iIh1A3y+yZTZaG505ZJMIAGCSqG" +
"SIb3DQEHATAdBglghkgBZQMEAQIEENmkYNbDXiZxJWtq82qIRZKggAQgkOGr" +
"1JcTsADStez1eY4+rO4DtyBIyUYQ3pilnbirfPkAAAAAAAAAAAAA");
CMSEnvelopedDataParser ep = new CMSEnvelopedDataParser(envData);
RecipientInformationStore recipients = ep.getRecipientInfos();
assertEquals(ep.getEncryptionAlgOID(), CMSEnvelopedDataGenerator.AES128_CBC);
Collection c = recipients.getRecipients();
Iterator it = c.iterator();
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyData);
KeyFactory keyFact = KeyFactory.getInstance("RSA", BC);
PrivateKey priKey = keyFact.generatePrivate(keySpec);
byte[] data = Hex.decode("57616c6c6157616c6c6157617368696e67746f6e");
while (it.hasNext())
{
RecipientInformation recipient = (RecipientInformation)it.next();
assertEquals(recipient.getKeyEncryptionAlgOID(), PKCSObjectIdentifiers.rsaEncryption.getId());
CMSTypedStream recData = recipient.getContentStream(new JceKeyTransEnvelopedRecipient(priKey).setProvider(BC));
assertEquals(true, Arrays.equals(data, CMSTestUtil.streamToByteArray(recData.getContentStream())));
}
}
示例5: testKeyTransAES128Throughput
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的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.");
}
}
示例6: testKeyTransAES128
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的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();
}
示例7: testKeyTransAES128
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的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();
}
示例8: testECKeyAgree
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的package包/类
public void testECKeyAgree()
throws Exception
{
byte[] data = Hex.decode("504b492d4320434d5320456e76656c6f706564446174612053616d706c65");
CMSEnvelopedDataStreamGenerator edGen = new CMSEnvelopedDataStreamGenerator();
JceKeyAgreeRecipientInfoGenerator recipientGenerator = new JceKeyAgreeRecipientInfoGenerator(CMSAlgorithm.ECDH_SHA1KDF, _origEcKP.getPrivate(), _origEcKP.getPublic(), CMSAlgorithm.AES128_WRAP).setProvider(BC);
recipientGenerator.addRecipient(_reciEcCert);
edGen.addRecipientInfoGenerator(recipientGenerator);
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);
RecipientId recSel = new JceKeyAgreeRecipientId(_reciEcCert);
RecipientInformation recipient = recipients.get(recSel);
CMSTypedStream recData = recipient.getContentStream(new JceKeyAgreeEnvelopedRecipient(_reciEcKP.getPrivate()).setProvider(BC));
assertEquals(true, Arrays.equals(data, CMSTestUtil.streamToByteArray(recData.getContentStream())));
ep.close();
}
示例9: testECKeyAgree
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的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();
}
示例10: testKeyTransCAST5SunJCE
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的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();
}
示例11: testAESKEK
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的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();
}
示例12: testKeyTransAES128AndOriginatorInfo
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的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();
}
示例13: testAESKEK
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的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();
}
示例14: testTwoAESKEK
import org.bouncycastle.cms.RecipientInformation; //导入方法依赖的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();
}