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


Java CMSEnvelopedDataStreamGenerator.addKeyTransRecipient方法代码示例

本文整理汇总了Java中org.bouncycastle.cms.CMSEnvelopedDataStreamGenerator.addKeyTransRecipient方法的典型用法代码示例。如果您正苦于以下问题:Java CMSEnvelopedDataStreamGenerator.addKeyTransRecipient方法的具体用法?Java CMSEnvelopedDataStreamGenerator.addKeyTransRecipient怎么用?Java CMSEnvelopedDataStreamGenerator.addKeyTransRecipient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bouncycastle.cms.CMSEnvelopedDataStreamGenerator的用法示例。


在下文中一共展示了CMSEnvelopedDataStreamGenerator.addKeyTransRecipient方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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.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

示例2: 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);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:38,代码来源:EnvelopedDataStreamTest.java

示例3: 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();
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:41,代码来源:EnvelopedDataStreamTest.java

示例4: 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();
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:52,代码来源:EnvelopedDataStreamTest.java


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