Package org.bouncycastle.cms

Examples of org.bouncycastle.cms.CMSEnvelopedDataParser


     * @throws Exception
     */
    public static void decrypt(final InputStream is, OutputStream os, Key key, String providerName) throws Exception  {
        final InputStream bis = new BufferedInputStream(is, bufferSize);
        final OutputStream bos = new BufferedOutputStream(os, bufferSize);
        final Iterator  it = new CMSEnvelopedDataParser(bis).getRecipientInfos().getRecipients().iterator();
        if (it.hasNext()) {
            final RecipientInformation recipient = (RecipientInformation)it.next();
            final CMSTypedStream recData = recipient.getContentStream(key, providerName);
            final InputStream ris = recData.getContentStream();
            fromInToOut(ris, bos);
View Full Code Here


                  "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);
View Full Code Here

        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())
View Full Code Here

            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())
        {
View Full Code Here

   
        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();
    }
View Full Code Here

        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();
    }
View Full Code Here

                                CMSEnvelopedDataGenerator.DES_EDE3_CBC, "BC");
        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(kek, "BC");
           
            assertEquals(true, Arrays.equals(data, CMSTestUtil.streamToByteArray(recData.getContentStream())));
        }
       
        ep.close();
    }
View Full Code Here

                                CMSEnvelopedDataGenerator.DES_EDE3_CBC, "BC");
        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 RecipientId();
       
        recSel.setKeyIdentifier(kekId2);
       
        RecipientInformation       recipient = recipients.get(recSel);
       
        assertEquals(recipient.getKeyEncryptionAlgOID(), "2.16.840.1.101.3.4.1.25");
       
        CMSTypedStream recData = recipient.getContentStream(kek2, "BC");
       
        assertEquals(true, Arrays.equals(data, CMSTestUtil.streamToByteArray(recData.getContentStream())));

        ep.close();
    }
View Full Code Here

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

        RecipientId                recSel = new RecipientId();

        recSel.setIssuer(PrincipalUtil.getIssuerX509Principal(_reciEcCert).getEncoded());
        recSel.setSerialNumber(_reciEcCert.getSerialNumber());

        RecipientInformation       recipient = recipients.get(recSel);

        CMSTypedStream recData = recipient.getContentStream(_reciEcKP.getPrivate(), "BC");

        assertEquals(true, Arrays.equals(data, CMSTestUtil.streamToByteArray(recData.getContentStream())));

        ep.close();
    }
View Full Code Here

    }

    public void testOriginatorInfo()
        throws Exception
    {
        CMSEnvelopedDataParser env = new CMSEnvelopedDataParser(CMSSampleMessages.originatorMessage);

        env.getRecipientInfos();

        assertEquals(CMSEnvelopedDataGenerator.DES_EDE3_CBC, env.getEncryptionAlgOID());
    }
View Full Code Here

TOP

Related Classes of org.bouncycastle.cms.CMSEnvelopedDataParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.