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


Java BcRSAKeyTransRecipientInfoGenerator類代碼示例

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


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

示例1: testKeyTransLight128RC4

import org.bouncycastle.cms.bc.BcRSAKeyTransRecipientInfoGenerator; //導入依賴的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");
    }
}
 
開發者ID:ttt43ttt,項目名稱:gwt-crypto,代碼行數:40,代碼來源:BcEnvelopedDataTest.java

示例2: testKeyTrans128RC4

import org.bouncycastle.cms.bc.BcRSAKeyTransRecipientInfoGenerator; //導入依賴的package包/類
public void testKeyTrans128RC4()
    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 BcCMSContentEncryptorBuilder(new ASN1ObjectIdentifier("1.2.840.113549.3.4"), 128).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 BcRSAKeyTransEnvelopedRecipient(PrivateKeyFactory.createKey(PrivateKeyInfo.getInstance(_reciKP.getPrivate().getEncoded()))));

        assertEquals(true, Arrays.equals(data, recData));
    }
    else
    {
        fail("no recipient found");
    }
}
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:34,代碼來源:BcEnvelopedDataTest.java

示例3: testKeyTransLight128RC4

import org.bouncycastle.cms.bc.BcRSAKeyTransRecipientInfoGenerator; //導入依賴的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 BcCMSContentEncryptorBuilder(new ASN1ObjectIdentifier("1.2.840.113549.3.4"), 128).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 BcRSAKeyTransEnvelopedRecipient(PrivateKeyFactory.createKey(PrivateKeyInfo.getInstance(_reciKP.getPrivate().getEncoded()))));

        assertEquals(true, Arrays.equals(data, recData));
    }
    else
    {
        fail("no recipient found");
    }
}
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:34,代碼來源:BcEnvelopedDataTest.java

示例4: testKeyTransODES

import org.bouncycastle.cms.bc.BcRSAKeyTransRecipientInfoGenerator; //導入依賴的package包/類
public void testKeyTransODES()
    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 BcCMSContentEncryptorBuilder(new ASN1ObjectIdentifier("1.3.14.3.2.7")).build());

    RecipientInformationStore  recipients = ed.getRecipientInfos();

    assertEquals(ed.getEncryptionAlgOID(), "1.3.14.3.2.7");

    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");
    }
}
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:34,代碼來源:BcEnvelopedDataTest.java

示例5: testKeyTransSmallAES

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

示例6: testKeyTransLight128RC4

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

示例7: testKeyTransDESEDE3Light

import org.bouncycastle.cms.bc.BcRSAKeyTransRecipientInfoGenerator; //導入依賴的package包/類
public void testKeyTransDESEDE3Light()
    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.DES_EDE3_CBC, 192).build());

    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();

        byte[] recData = recipient.getContent(new JceKeyTransEnvelopedRecipient(_reciKP.getPrivate()).setProvider(BC));
        assertEquals(true, Arrays.equals(data, recData));
    }
    else
    {
        fail("no recipient found");
    }
}
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:34,代碼來源:NewEnvelopedDataTest.java

示例8: tryKeyTrans

import org.bouncycastle.cms.bc.BcRSAKeyTransRecipientInfoGenerator; //導入依賴的package包/類
private void tryKeyTrans(ASN1ObjectIdentifier generatorOID, ASN1ObjectIdentifier checkOID, int keySize, Class asn1Params)
    throws Exception
{
    byte[]          data     = "WallaWallaWashington".getBytes();

    CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();

    edGen.addRecipientInfoGenerator(new BcRSAKeyTransRecipientInfoGenerator(new JcaX509CertificateHolder(_reciCert)));

    OutputEncryptor encryptor = new BcCMSContentEncryptorBuilder(generatorOID).build();
    CMSEnvelopedData ed = edGen.generate(
                            new CMSProcessableByteArray(data), encryptor);

    RecipientInformationStore  recipients = ed.getRecipientInfos();

    assertEquals(checkOID.getId(), ed.getEncryptionAlgOID());
    assertEquals(keySize, ((byte[])encryptor.getKey().getRepresentation()).length);

    if (asn1Params != null)
    {
        assertTrue(asn1Params.isAssignableFrom(ed.getContentEncryptionAlgorithm().getParameters().toASN1Primitive().getClass()));
    }

    Collection c = recipients.getRecipients();

    assertEquals(1, c.size());

    Iterator it = c.iterator();

    if (!it.hasNext())
    {
        fail("no recipients found");
    }

    while (it.hasNext())
    {
        RecipientInformation   recipient = (RecipientInformation)it.next();

        assertEquals(recipient.getKeyEncryptionAlgOID(), PKCSObjectIdentifiers.rsaEncryption.getId());

        byte[] recData = recipient.getContent(new BcRSAKeyTransEnvelopedRecipient(PrivateKeyFactory.createKey(PrivateKeyInfo.getInstance(_reciKP.getPrivate().getEncoded()))));

        assertEquals(true, Arrays.equals(data, recData));
    }
}
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:46,代碼來源:BcEnvelopedDataTest.java

示例9: testKeyTrans

import org.bouncycastle.cms.bc.BcRSAKeyTransRecipientInfoGenerator; //導入依賴的package包/類
public void testKeyTrans()
    throws Exception
{
    byte[]          data     = "WallaWallaWashington".getBytes();

    CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();

    edGen.addRecipientInfoGenerator(new BcRSAKeyTransRecipientInfoGenerator(new JcaX509CertificateHolder(_reciCert)));

    CMSEnvelopedData ed = edGen.generate(
                            new CMSProcessableByteArray(data),
                            new BcCMSContentEncryptorBuilder(CMSAlgorithm.DES_EDE3_CBC).build());

    RecipientInformationStore  recipients = ed.getRecipientInfos();


    assertEquals(ed.getEncryptionAlgOID(), CMSAlgorithm.DES_EDE3_CBC.getId());

    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 BcRSAKeyTransEnvelopedRecipient(PrivateKeyFactory.createKey(PrivateKeyInfo.getInstance(_reciKP.getPrivate().getEncoded()))));

        assertEquals(true, Arrays.equals(data, recData));
    }
}
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:36,代碼來源:BcEnvelopedDataTest.java

示例10: testKeyTransRC4

import org.bouncycastle.cms.bc.BcRSAKeyTransRecipientInfoGenerator; //導入依賴的package包/類
public void testKeyTransRC4()
    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 BcCMSContentEncryptorBuilder(new ASN1ObjectIdentifier("1.2.840.113549.3.4")).build());

    RecipientInformationStore  recipients = ed.getRecipientInfos();

    assertEquals(ed.getEncryptionAlgOID(), new ASN1ObjectIdentifier("1.2.840.113549.3.4").getId());

    Collection c = recipients.getRecipients();

    assertEquals(1, c.size());

    Iterator it = c.iterator();

    while (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));
    }
}
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:33,代碼來源:BcEnvelopedDataTest.java

示例11: testUnprotectedAttributes

import org.bouncycastle.cms.bc.BcRSAKeyTransRecipientInfoGenerator; //導入依賴的package包/類
public void testUnprotectedAttributes()
    throws Exception
{
    byte[]          data     = "WallaWallaWashington".getBytes();

    CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();

    edGen.addRecipientInfoGenerator(new BcRSAKeyTransRecipientInfoGenerator(new JcaX509CertificateHolder(_reciCert)));

    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));

    CMSEnvelopedData ed = edGen.generate(
        new CMSProcessableByteArray(data),
        new BcCMSContentEncryptorBuilder(CMSAlgorithm.DES_EDE3_CBC).build());

    RecipientInformationStore  recipients = ed.getRecipientInfos();

    assertEquals(ed.getEncryptionAlgOID(), CMSAlgorithm.DES_EDE3_CBC.getId());

    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));
            
    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 BcRSAKeyTransEnvelopedRecipient(PrivateKeyFactory.createKey(_reciKP.getPrivate().getEncoded())));

        assertEquals(true, Arrays.equals(data, recData));
    }
}
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:51,代碼來源:BcEnvelopedDataTest.java


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