當前位置: 首頁>>代碼示例>>Java>>正文


Java CMSEnvelopedDataParser類代碼示例

本文整理匯總了Java中org.bouncycastle.cms.CMSEnvelopedDataParser的典型用法代碼示例。如果您正苦於以下問題:Java CMSEnvelopedDataParser類的具體用法?Java CMSEnvelopedDataParser怎麽用?Java CMSEnvelopedDataParser使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CMSEnvelopedDataParser類屬於org.bouncycastle.cms包,在下文中一共展示了CMSEnvelopedDataParser類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: verifyData

import org.bouncycastle.cms.CMSEnvelopedDataParser; //導入依賴的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())));
    }
}
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:26,代碼來源:NewEnvelopedDataStreamTest.java

示例2: verifyData

import org.bouncycastle.cms.CMSEnvelopedDataParser; //導入依賴的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())));
    }
}
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:26,代碼來源:EnvelopedDataStreamTest.java

示例3: verifyEnvelopedData

import org.bouncycastle.cms.CMSEnvelopedDataParser; //導入依賴的package包/類
private void verifyEnvelopedData(CMSEnvelopedDataParser envelopedParser, String symAlgorithmOID)
    throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException, CMSException
{
    byte[]              privKeyData = getRfc4134Data("BobPrivRSAEncrypt.pri");
    PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(privKeyData);
    KeyFactory keyFact = KeyFactory.getInstance("RSA", BC);
    PrivateKey privKey = keyFact.generatePrivate(keySpec);

    RecipientInformationStore recipients = envelopedParser.getRecipientInfos();

    assertEquals(envelopedParser.getEncryptionAlgOID(), symAlgorithmOID);

    Collection c = recipients.getRecipients();
    assertTrue(c.size() >= 1 && c.size() <= 2);

    Iterator it = c.iterator();
    verifyRecipient((RecipientInformation)it.next(), privKey);

    if (c.size() == 2)
    {
        RecipientInformation recInfo = (RecipientInformation)it.next();

        assertEquals(PKCSObjectIdentifiers.id_alg_CMSRC2wrap.getId(), recInfo.getKeyEncryptionAlgOID());
    }
}
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:26,代碼來源:Rfc4134Test.java

示例4: testOriginatorInfo

import org.bouncycastle.cms.CMSEnvelopedDataParser; //導入依賴的package包/類
public void testOriginatorInfo()
    throws Exception
{
    CMSEnvelopedDataParser env = new CMSEnvelopedDataParser(CMSSampleMessages.originatorMessage);

    OriginatorInformation origInfo = env.getOriginatorInfo();

    RecipientInformationStore  recipients = env.getRecipientInfos();

    assertEquals(new X500Name("C=US,O=U.S. Government,OU=HSPD12Lab,OU=Agents,CN=user1"), ((X509CertificateHolder)origInfo.getCertificates().getMatches(null).iterator().next()).getSubject());
    assertEquals(CMSEnvelopedDataGenerator.DES_EDE3_CBC, env.getEncryptionAlgOID());
}
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:13,代碼來源:NewEnvelopedDataStreamTest.java

示例5: testOriginatorInfo

import org.bouncycastle.cms.CMSEnvelopedDataParser; //導入依賴的package包/類
public void testOriginatorInfo()
    throws Exception
{
    CMSEnvelopedDataParser env = new CMSEnvelopedDataParser(CMSSampleMessages.originatorMessage);

    env.getRecipientInfos();

    assertEquals(CMSEnvelopedDataGenerator.DES_EDE3_CBC, env.getEncryptionAlgOID());
}
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:10,代碼來源:EnvelopedDataStreamTest.java

示例6: test5_1

import org.bouncycastle.cms.CMSEnvelopedDataParser; //導入依賴的package包/類
public void test5_1()
    throws Exception
{
    byte[] data = getRfc4134Data("5.1.bin");
    CMSEnvelopedData envelopedData = new CMSEnvelopedData(data);

    verifyEnvelopedData(envelopedData, CMSEnvelopedDataGenerator.DES_EDE3_CBC);

    CMSEnvelopedDataParser envelopedParser = new CMSEnvelopedDataParser(data);

    verifyEnvelopedData(envelopedParser, CMSEnvelopedDataGenerator.DES_EDE3_CBC);
}
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:13,代碼來源:Rfc4134Test.java

示例7: test5_2

import org.bouncycastle.cms.CMSEnvelopedDataParser; //導入依賴的package包/類
public void test5_2()
    throws Exception
{
    byte[] data = getRfc4134Data("5.2.bin");
    CMSEnvelopedData envelopedData = new CMSEnvelopedData(data);

    verifyEnvelopedData(envelopedData, CMSEnvelopedDataGenerator.RC2_CBC);

    CMSEnvelopedDataParser envelopedParser = new CMSEnvelopedDataParser(data);

    verifyEnvelopedData(envelopedParser, CMSEnvelopedDataGenerator.RC2_CBC);
}
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:13,代碼來源:Rfc4134Test.java

示例8: testSeal

import org.bouncycastle.cms.CMSEnvelopedDataParser; //導入依賴的package包/類
@Test
public void testSeal() throws Exception {
	InputStream sealInputStream = SealTest.class
			.getResourceAsStream("/seal-fcorneli.der");
	assertNotNull(sealInputStream);
	byte[] cmsData = IOUtils.toByteArray(sealInputStream);

	// check outer signature
	byte[] data = getVerifiedContent(cmsData);

	// decrypt content

	CMSEnvelopedDataParser cmsEnvelopedDataParser = new CMSEnvelopedDataParser(
			data);
	LOG.debug("content encryption algo: "
			+ cmsEnvelopedDataParser.getContentEncryptionAlgorithm()
					.getAlgorithm().getId());

	RecipientInformationStore recipientInformationStore = cmsEnvelopedDataParser
			.getRecipientInfos();
	Collection<RecipientInformation> recipients = recipientInformationStore
			.getRecipients();
	RecipientInformation recipientInformation = recipients.iterator()
			.next();
	LOG.debug("recipient info type: "
			+ recipientInformation.getClass().getName());
	KeyTransRecipientInformation keyTransRecipientInformation = (KeyTransRecipientInformation) recipientInformation;

	// load eHealth encryption certificate
	KeyStore eHealthKeyStore = KeyStore.getInstance("PKCS12");
	FileInputStream fileInputStream = new FileInputStream(
			this.config.getEHealthPKCS12Path());
	eHealthKeyStore.load(fileInputStream, this.config
			.getEHealthPKCS12Password().toCharArray());
	Enumeration<String> aliasesEnum = eHealthKeyStore.aliases();
	aliasesEnum.nextElement(); // skip authentication certificate.
	String alias = aliasesEnum.nextElement();
	X509Certificate eHealthCertificate = (X509Certificate) eHealthKeyStore
			.getCertificate(alias);
	PrivateKey eHealthPrivateKey = (PrivateKey) eHealthKeyStore.getKey(
			alias, this.config.getEHealthPKCS12Password().toCharArray());

	AsymmetricKeyParameter privKeyParams = PrivateKeyFactory
			.createKey(eHealthPrivateKey.getEncoded());
	BcRSAKeyTransEnvelopedRecipient recipient = new BcRSAKeyTransEnvelopedRecipient(
			privKeyParams);
	byte[] decryptedContent = recipientInformation.getContent(recipient);
	assertNotNull(decryptedContent);
	LOG.debug("decrypted content size: " + decryptedContent.length);

	byte[] result = getVerifiedContent(decryptedContent);
	LOG.debug("result: " + new String(result));
}
 
開發者ID:e-Contract,項目名稱:mycarenet,代碼行數:54,代碼來源:SealTest.java

示例9: testSeal

import org.bouncycastle.cms.CMSEnvelopedDataParser; //導入依賴的package包/類
@Test
public void testSeal() throws Exception {
	InputStream sealInputStream = SealTest.class
			.getResourceAsStream("/seal-fcorneli.der");
	assertNotNull(sealInputStream);

	// check outer signature

	CMSSignedData cmsSignedData = new CMSSignedData(sealInputStream);
	SignerInformationStore signers = cmsSignedData.getSignerInfos();
	SignerInformation signer = (SignerInformation) signers.getSigners()
			.iterator().next();
	SignerId signerId = signer.getSID();

	Store certificateStore = cmsSignedData.getCertificates();
	@SuppressWarnings("unchecked")
	Collection<X509CertificateHolder> certificateCollection = certificateStore
			.getMatches(signerId);
	X509CertificateHolder certificateHolder = certificateCollection
			.iterator().next();
	CertificateFactory certificateFactory = CertificateFactory
			.getInstance("X.509");
	X509Certificate certificate = (X509Certificate) certificateFactory
			.generateCertificate(new ByteArrayInputStream(certificateHolder
					.getEncoded()));

	Security.addProvider(new BouncyCastleProvider());
	SignerInformationVerifier signerInformationVerifier = new JcaSimpleSignerInfoVerifierBuilder()
			.build(certificate);
	boolean signatureResult = signer.verify(signerInformationVerifier);
	assertTrue(signatureResult);

	LOG.debug("signer certificate: " + certificate);

	CMSTypedData signedContent = cmsSignedData.getSignedContent();
	byte[] data = (byte[]) signedContent.getContent();

	// decrypt content

	CMSEnvelopedDataParser cmsEnvelopedDataParser = new CMSEnvelopedDataParser(
			data);
	LOG.debug("content encryption algo: "
			+ cmsEnvelopedDataParser.getContentEncryptionAlgorithm()
					.getAlgorithm().getId());

	RecipientInformationStore recipientInformationStore = cmsEnvelopedDataParser
			.getRecipientInfos();
	@SuppressWarnings("unchecked")
	Collection<RecipientInformation> recipients = recipientInformationStore
			.getRecipients();
	RecipientInformation recipientInformation = recipients.iterator()
			.next();
	LOG.debug("recipient info type: "
			+ recipientInformation.getClass().getName());
	KeyTransRecipientInformation keyTransRecipientInformation = (KeyTransRecipientInformation) recipientInformation;

}
 
開發者ID:e-Contract,項目名稱:mycarenet,代碼行數:58,代碼來源:SealTest.java

示例10: testWorkingData

import org.bouncycastle.cms.CMSEnvelopedDataParser; //導入依賴的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())));
    }
}
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:56,代碼來源:NewEnvelopedDataStreamTest.java

示例11: testKeyTransAES128Throughput

import org.bouncycastle.cms.CMSEnvelopedDataParser; //導入依賴的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.");
    }
}
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:68,代碼來源:NewEnvelopedDataStreamTest.java

示例12: testWorkingData

import org.bouncycastle.cms.CMSEnvelopedDataParser; //導入依賴的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())));
    }
}
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:56,代碼來源:EnvelopedDataStreamTest.java

示例13: testKeyTransAES128Throughput

import org.bouncycastle.cms.CMSEnvelopedDataParser; //導入依賴的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.");
    }
}
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:68,代碼來源:EnvelopedDataStreamTest.java

示例14: testKeyTransAES128

import org.bouncycastle.cms.CMSEnvelopedDataParser; //導入依賴的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();
}
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:41,代碼來源:NewEnvelopedDataStreamTest.java

示例15: testECKeyAgree

import org.bouncycastle.cms.CMSEnvelopedDataParser; //導入依賴的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();
}
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:39,代碼來源:NewEnvelopedDataStreamTest.java


注:本文中的org.bouncycastle.cms.CMSEnvelopedDataParser類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。