當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。