Examples of CipherOutputStream


Examples of javax.crypto.CipherOutputStream

        throws Exception
    {
        Key key;
        Cipher in, out;
        CipherInputStream cIn;
        CipherOutputStream cOut;
        ByteArrayInputStream bIn;
        ByteArrayOutputStream bOut;

        key = new SecretKeySpec(keyBytes, "Noekeon");

        in = Cipher.getInstance("Noekeon/ECB/NoPadding", "BC");
        out = Cipher.getInstance("Noekeon/ECB/NoPadding", "BC");

        try
        {
            out.init(Cipher.ENCRYPT_MODE, key);
        }
        catch (Exception e)
        {
            fail("Noekeon failed initialisation - " + e.toString(), e);
        }

        try
        {
            in.init(Cipher.DECRYPT_MODE, key);
        }
        catch (Exception e)
        {
            fail("Noekeoen failed initialisation - " + e.toString(), e);
        }

        //
        // encryption pass
        //
        bOut = new ByteArrayOutputStream();

        cOut = new CipherOutputStream(bOut, out);

        try
        {
            for (int i = 0; i != input.length / 2; i++)
            {
                cOut.write(input[i]);
            }
            cOut.write(input, input.length / 2, input.length - input.length / 2);
            cOut.close();
        }
        catch (IOException e)
        {
            fail("Noekeon failed encryption - " + e.toString(), e);
        }
View Full Code Here

Examples of javax.crypto.CipherOutputStream

            dOut.write(salt);
            dOut.writeInt(iterationCount);
   
            cipher = this.makePBECipher(STORE_CIPHER, Cipher.ENCRYPT_MODE, password, salt, iterationCount);
   
            CipherOutputStream  cOut = new CipherOutputStream(dOut, cipher);
            DigestOutputStream  dgOut = new DigestOutputStream(cOut, new SHA1Digest());
   
            this.saveStore(dgOut);
   
            Digest  dig = dgOut.getDigest();
            byte[]  hash = new byte[dig.getDigestSize()];
   
            dig.doFinal(hash, 0);
   
            cOut.write(hash);
   
            cOut.close();
        }
View Full Code Here

Examples of javax.crypto.CipherOutputStream

            dOut.writeInt(salt.length);
            dOut.write(salt);
            dOut.writeInt(iterationCount);

            Cipher              cipher = makePBECipher(KEY_CIPHER, Cipher.ENCRYPT_MODE, password, salt, iterationCount);
            CipherOutputStream  cOut = new CipherOutputStream(dOut, cipher);

            dOut = new DataOutputStream(cOut);

            encodeKey(key, dOut);
View Full Code Here

Examples of javax.crypto.CipherOutputStream

                            dOut.writeInt(salt.length);
                            dOut.write(salt);
                            dOut.writeInt(iterationCount);

                            Cipher              out = makePBECipher(KEY_CIPHER, Cipher.ENCRYPT_MODE, password, salt, iterationCount);
                            CipherOutputStream  cOut = new CipherOutputStream(dOut, out);

                            dOut = new DataOutputStream(cOut);

                            encodeKey(k, dOut);
View Full Code Here

Examples of javax.crypto.CipherOutputStream

        throws Exception
    {
        Key key;
        Cipher in, out;
        CipherInputStream cIn;
        CipherOutputStream cOut;
        ByteArrayInputStream bIn;
        ByteArrayOutputStream bOut;

        key = new SecretKeySpec(keyBytes, "SEED");

        in = Cipher.getInstance("SEED/ECB/NoPadding", "BC");
        out = Cipher.getInstance("SEED/ECB/NoPadding", "BC");

        try
        {
            out.init(Cipher.ENCRYPT_MODE, key);
        }
        catch (Exception e)
        {
            fail("SEED failed initialisation - " + e.toString(), e);
        }

        try
        {
            in.init(Cipher.DECRYPT_MODE, key);
        }
        catch (Exception e)
        {
            fail("SEED failed initialisation - " + e.toString(), e);
        }

        //
        // encryption pass
        //
        bOut = new ByteArrayOutputStream();

        cOut = new CipherOutputStream(bOut, out);

        try
        {
            for (int i = 0; i != input.length / 2; i++)
            {
                cOut.write(input[i]);
            }
            cOut.write(input, input.length / 2, input.length - input.length / 2);
            cOut.close();
        }
        catch (IOException e)
        {
            fail("SEED failed encryption - " + e.toString(), e);
        }
View Full Code Here

Examples of javax.crypto.CipherOutputStream

        throws Exception
    {
        Key key;
        Cipher in, out;
        CipherInputStream cIn;
        CipherOutputStream cOut;
        ByteArrayInputStream bIn;
        ByteArrayOutputStream bOut;

        key = new SecretKeySpec(keyBytes, "Camellia");

        in = Cipher.getInstance("Camellia/ECB/NoPadding", "BC");
        out = Cipher.getInstance("Camellia/ECB/NoPadding", "BC");

        try
        {
            out.init(Cipher.ENCRYPT_MODE, key);
        }
        catch (Exception e)
        {
            fail("Camellia failed initialisation - " + e.toString(), e);
        }

        try
        {
            in.init(Cipher.DECRYPT_MODE, key);
        }
        catch (Exception e)
        {
            fail("Camellia failed initialisation - " + e.toString(), e);
        }

        //
        // encryption pass
        //
        bOut = new ByteArrayOutputStream();

        cOut = new CipherOutputStream(bOut, out);

        try
        {
            for (int i = 0; i != input.length / 2; i++)
            {
                cOut.write(input[i]);
            }
            cOut.write(input, input.length / 2, input.length - input.length / 2);
            cOut.close();
        }
        catch (IOException e)
        {
            fail("Camellia failed encryption - " + e.toString(), e);
        }
View Full Code Here

Examples of javax.crypto.CipherOutputStream

      output.flush();
     
      //EOS intercepts the close() call and does not close the stream
      EncryptionOutputStream eos = new EncryptionOutputStream(output);
      
      CipherOutputStream cos = new CipherOutputStream(eos, cipher);
      
      SerializationManager sm = SerializationStreamFactory.getManagerInstance(getSerializationType());
      ObjectOutputStream oos = sm.createOutput(cos);
     
      if(wrappedMarshaller != null)
      {
         if (wrappedMarshaller instanceof VersionedMarshaller)
            ((VersionedMarshaller) wrappedMarshaller).write(dataObject, oos, version);
         else
            wrappedMarshaller.write(dataObject, oos);
      }
      else
      {
         super.write(dataObject, oos, version);
     
      oos.flush()
     
      //Vagaries of CipherOutputStream which needs a close() to flush at the end
      cos.close(); //Tests fail without this statement - oos.close() should do it
      oos.close(); //There is a need to close cos
   }
View Full Code Here

Examples of javax.crypto.CipherOutputStream

            out.write(asym.doFinal(symKey.getEncoded()));

            // the rest of the data will be encrypted by this symmetric cipher
            Cipher sym = Secret.getCipher(algorithm);
            sym.init(Cipher.ENCRYPT_MODE,symKey, keyAlgorithm.equals(algorithm) ? null : new IvParameterSpec(symKey.getEncoded()));
            super.out = new CipherOutputStream(out,sym);
        }
View Full Code Here

Examples of javax.crypto.CipherOutputStream

        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            Cipher sym = Secret.getCipher("AES");
            sym.init(Cipher.ENCRYPT_MODE, Jenkins.getInstance().getSecretKeyAsAES128());
            ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(new CipherOutputStream(baos,sym)));
            oos.writeLong(System.currentTimeMillis()); // send timestamp to prevent a replay attack
            oos.writeObject(caw.getConsoleAnnotator());
            oos.close();
            StaplerResponse rsp = Stapler.getCurrentResponse();
            if (rsp!=null)
View Full Code Here

Examples of javax.crypto.CipherOutputStream

    keySpec = new SecretKeySpec(key, "Blowfish");
  }

  public void write (Kryo kryo, Output output, Object object) {
    Cipher cipher = getCipher(Cipher.ENCRYPT_MODE);
    CipherOutputStream cipherStream = new CipherOutputStream(output, cipher);
    Output cipherOutput = new Output(cipherStream, 256) {
      public void close () throws KryoException {
        // Don't allow the CipherOutputStream to close the output.
      }
    };
    kryo.writeObject(cipherOutput, object, serializer);
    cipherOutput.flush();
    try {
      cipherStream.close();
    } catch (IOException ex) {
      throw new KryoException(ex);
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.