Package org.bouncycastle.cms

Examples of org.bouncycastle.cms.CMSEnvelopedDataStreamGenerator


     * @throws Exception
     */
    public static void encrypt(final InputStream is, OutputStream os, X509Certificate cert) throws Exception {
        final InputStream bis = new BufferedInputStream(is, bufferSize);
        final OutputStream bos = new BufferedOutputStream(os, bufferSize);
        final CMSEnvelopedDataStreamGenerator edGen = new CMSEnvelopedDataStreamGenerator();
        edGen.addKeyTransRecipient(cert.getPublicKey(), "hej".getBytes() );
        final OutputStream out = edGen.open(bos, CMSEnvelopedGenerator.AES128_CBC, "BC");
        fromInToOut(bis, out);
        bos.close();
        os.close();
    }
View Full Code Here


                 .setProvider("BC")
                 .build();
         if (out.getCertificate() == null) throw new NullPointerException("The certificate object was not set.");
         JceKeyTransRecipientInfoGenerator infoGenerator = new JceKeyTransRecipientInfoGenerator(out.getCertificate());
         infoGenerator.setProvider("BC");
         CMSEnvelopedDataStreamGenerator generator = new CMSEnvelopedDataStreamGenerator();
         generator.addRecipientInfoGenerator(infoGenerator);


         MimeBodyPart _msg = createBodyPart(providers, out);

         baos = new ByteArrayOutputStream();
         encrypted = generator.open(baos, encryptor);

         _msg.writeTo(encrypted);
         encrypted.close();
         byte[] bytes = baos.toByteArray();
         String str = Base64.encodeBytes(bytes, Base64.DO_BREAK_LINES);
View Full Code Here

   {
      OutputEncryptor encryptor = new JceCMSContentEncryptorBuilder(CMSAlgorithm.DES_EDE3_CBC)
              .setProvider("BC")
              .build();
      JceKeyTransRecipientInfoGenerator infoGenerator = new JceKeyTransRecipientInfoGenerator(cert);
      CMSEnvelopedDataStreamGenerator generator = new CMSEnvelopedDataStreamGenerator();
      generator.addRecipientInfoGenerator(infoGenerator);


      InternetHeaders ih = new InternetHeaders();
      ih.addHeader("Content-Type", "application/xml");

      MimeBodyPart _msg = new MimeBodyPart(ih, "<customer name=\"bill\"/>".getBytes());

      ByteArrayOutputStream os = new ByteArrayOutputStream();
      OutputStream encrypted = generator.open(os, encryptor);

      _msg.writeTo(encrypted);
      encrypted.close();

      String str = Base64.encodeBytes(os.toByteArray(), Base64.DO_BREAK_LINES);
View Full Code Here

        }
       
        //
        // unbuffered
        //
        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();
       
        verifyData(bOut, CMSEnvelopedDataGenerator.AES128_CBC, data);
       
        int unbufferedLength = bOut.toByteArray().length;
       
        //
        // Using buffered output - should be == to unbuffered
        //
        edGen = new CMSEnvelopedDataStreamGenerator();
   
        edGen.addKeyTransRecipient(_reciCert);
   
        bOut = new ByteArrayOutputStream();
       
        out = edGen.open(bOut, CMSEnvelopedDataGenerator.AES128_CBC, "BC");
   
        BufferedOutputStream bfOut = new BufferedOutputStream(out, 300);
       
        for (int i = 0; i != 2000; i++)
        {
View Full Code Here

        }
       
        //
        // unbuffered
        //
        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();
       
        verifyData(bOut, CMSEnvelopedDataGenerator.AES128_CBC, data);
       
        int unbufferedLength = bOut.toByteArray().length;
       
        //
        // buffered - less than default of 1000
        //
        edGen = new CMSEnvelopedDataStreamGenerator();
   
        edGen.setBufferSize(300);
       
        edGen.addKeyTransRecipient(_reciCert);
   
        bOut = new ByteArrayOutputStream();
       
        out = edGen.open(bOut, CMSEnvelopedDataGenerator.AES128_CBC, "BC");
   
        for (int i = 0; i != 2000; i++)
        {
            out.write(data[i]);
        }
View Full Code Here

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

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

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

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

        throws Exception
    {
        byte[]    data = "WallaWallaWashington".getBytes();
        SecretKey kek  = CMSTestUtil.makeAES192Key();
       
        CMSEnvelopedDataStreamGenerator edGen = new CMSEnvelopedDataStreamGenerator();

        byte[]  kekId = new byte[] { 1, 2, 3, 4, 5 };

        edGen.addKEKRecipient(kek, kekId);

        ByteArrayOutputStream  bOut = new ByteArrayOutputStream();
       
        OutputStream out = edGen.open(
                                bOut,
                                CMSEnvelopedDataGenerator.DES_EDE3_CBC, "BC");
        out.write(data);
       
        out.close();
View Full Code Here

TOP

Related Classes of org.bouncycastle.cms.CMSEnvelopedDataStreamGenerator

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.