当前位置: 首页>>代码示例>>Java>>正文


Java JceKEKEnvelopedRecipient类代码示例

本文整理汇总了Java中org.bouncycastle.cms.jcajce.JceKEKEnvelopedRecipient的典型用法代码示例。如果您正苦于以下问题:Java JceKEKEnvelopedRecipient类的具体用法?Java JceKEKEnvelopedRecipient怎么用?Java JceKEKEnvelopedRecipient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JceKEKEnvelopedRecipient类属于org.bouncycastle.cms.jcajce包,在下文中一共展示了JceKEKEnvelopedRecipient类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testErroneousKEK

import org.bouncycastle.cms.jcajce.JceKEKEnvelopedRecipient; //导入依赖的package包/类
public void testErroneousKEK()
    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(new JceKEKEnvelopedRecipient(kek).setProvider(BC));

        assertEquals(true, Arrays.equals(data, recData));
    }
    else
    {
        fail("no recipient found");
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:31,代码来源:NewEnvelopedDataTest.java

示例2: tryKekAlgorithm

import org.bouncycastle.cms.jcajce.JceKEKEnvelopedRecipient; //导入依赖的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");
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:37,代码来源:NewEnvelopedDataTest.java

示例3: testAESKEK

import org.bouncycastle.cms.jcajce.JceKEKEnvelopedRecipient; //导入依赖的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();
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:44,代码来源:NewEnvelopedDataStreamTest.java

示例4: testTwoAESKEK

import org.bouncycastle.cms.jcajce.JceKEKEnvelopedRecipient; //导入依赖的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();
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:43,代码来源:NewEnvelopedDataStreamTest.java


注:本文中的org.bouncycastle.cms.jcajce.JceKEKEnvelopedRecipient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。