Package javax.crypto

Examples of javax.crypto.CipherInputStream


   
                IvParameterSpec ips = new IvParameterSpec(iv);
   
                decryptCipher.init(decrypt ? Cipher.DECRYPT_MODE : Cipher.ENCRYPT_MODE, aesKey, ips);
   
                CipherInputStream cipherStream = new CipherInputStream(data, decryptCipher);
               
                try {
                    byte buffer[] = new byte[4096];
                    long count = 0L;
                    for(int n = 0; -1 != (n = cipherStream.read(buffer));)
                    {
                        output.write(buffer, 0, n);
                        count += n;
                    }
                }
                finally {
                    cipherStream.close();
                }
            }
            catch (InvalidKeyException e) {
                throw new WrappedIOException(e);
            }
View Full Code Here


   
                IvParameterSpec ips = new IvParameterSpec(iv);
   
                decryptCipher.init(decrypt ? Cipher.DECRYPT_MODE : Cipher.ENCRYPT_MODE, aesKey, ips);
   
                CipherInputStream cipherStream = new CipherInputStream(data, decryptCipher);
               
                try {
                    byte buffer[] = new byte[4096];
                    long count = 0L;
                    for(int n = 0; -1 != (n = cipherStream.read(buffer));)
                    {
                        output.write(buffer, 0, n);
                        count += n;
                    }
                }
                finally {
                    cipherStream.close();
                }
            }
            catch (InvalidKeyException e) {
                throw new WrappedIOException(e);
            }
View Full Code Here

     */
    public InputStream getInputStream( InputStream is )
        throws GeneralSecurityException, IOException
    {
        Cipher cipher = this.createCipher( Cipher.DECRYPT_MODE, PasswordFactory.create() );
        return new CipherInputStream( is, cipher );
    }
View Full Code Here

     */
    public InputStream getInputStream( InputStream is, char[] password )
        throws GeneralSecurityException, IOException
    {
        Cipher cipher = this.createCipher( Cipher.DECRYPT_MODE, password );
        return new CipherInputStream( is, cipher );
    }
View Full Code Here

                    int     iterationCount = dIn.readInt();
               
                    Cipher      cipher = makePBECipher(KEY_CIPHER, Cipher.DECRYPT_MODE, password, salt, iterationCount);

                    CipherInputStream cIn = new CipherInputStream(dIn, cipher);

                    try
                    {
                        return decodeKey(new DataInputStream(cIn));
                    }
                    catch (Exception x)
                    {
                        bIn = new ByteArrayInputStream((byte[])obj);
                        dIn = new DataInputStream(bIn);
           
                        salt = new byte[dIn.readInt()];

                        dIn.readFully(salt);

                        iterationCount = dIn.readInt();

                        cipher = makePBECipher("Broken" + KEY_CIPHER, Cipher.DECRYPT_MODE, password, salt, iterationCount);

                        cIn = new CipherInputStream(dIn, cipher);

                        Key k = null;

                        try
                        {
                            k = decodeKey(new DataInputStream(cIn));
                        }
                        catch (Exception y)
                        {
                            bIn = new ByteArrayInputStream((byte[])obj);
                            dIn = new DataInputStream(bIn);
               
                            salt = new byte[dIn.readInt()];

                            dIn.readFully(salt);

                            iterationCount = dIn.readInt();

                            cipher = makePBECipher("Old" + KEY_CIPHER, Cipher.DECRYPT_MODE, password, salt, iterationCount);

                            cIn = new CipherInputStream(dIn, cipher);

                            k = decodeKey(new DataInputStream(cIn));
                        }

                        //
View Full Code Here

            else
            {
                cipher = this.makePBECipher(STORE_CIPHER, Cipher.DECRYPT_MODE, password, salt, iterationCount);
            }
   
            CipherInputStream  cIn = new CipherInputStream(dIn, cipher);
   
            DigestInputStream  dgIn = new DigestInputStream(cIn, new SHA1Digest());
   
            this.loadStore(dgIn);
   
            Digest  dig = dgIn.getDigest();
            int     digSize = dig.getDigestSize();
            byte[]  hash = new byte[digSize];
            byte[]  oldHash = new byte[digSize];
   
            dig.doFinal(hash, 0);
   
            for (int i = 0; i != digSize; i++)
            {
                oldHash[i] = (byte)cIn.read();
            }
   
            if (!this.isSameAs(hash, oldHash))
            {
                table.clear();
View Full Code Here

                final SecretKey aesKey = new SecretKeySpec(aesKeyBytes, "AES");
                try {
                    final Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
                    cipher.init(Cipher.DECRYPT_MODE, aesKey, new IvParameterSpec(iv));
                    cipherInputStream = new CipherInputStream(in, cipher);
                    isInitialized = true;
                    return cipherInputStream;
                } catch (GeneralSecurityException generalSecurityException) {
                    IOException ioe = new IOException("Decryption error " +
                                                      "(do you have the JCE Unlimited Strength Jurisdiction Policy Files installed?)");
View Full Code Here

   public abstract Cipher initializeCipher(Key key);

   @Override
   public CipherInputStream getInput() {
      return new CipherInputStream(super.getInput(), initializeCipher(key));
   }
View Full Code Here

            m_cipher.init(Cipher.DECRYPT_MODE, Synergizer.getMultitasker(m_algorithm));

            byte[] bytePassword = Helper.buildBytesFromHexString(encryptedPswd);

            ByteArrayInputStream bais = new ByteArrayInputStream(bytePassword);
            CipherInputStream cis = new CipherInputStream(bais, m_cipher);
            ObjectInputStream ois = new ObjectInputStream(cis);

            password = (String)ois.readObject();
            ois.close();
        } catch (IOException e) {
View Full Code Here

                 useCipher = true;
             }
         }
        
         if (useCipher) {
             return new CipherInputStream(new FileInputStream(file), _cipher.getEcipher());
         }
         else {
             return new FileInputStream(file);
         }
        
View Full Code Here

TOP

Related Classes of javax.crypto.CipherInputStream

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.