Examples of CipherInputStream


Examples of javax.crypto.CipherInputStream

    } catch (InvalidAlgorithmParameterException e) {
      log.error("Error when trying to initialize cipher with initialization vector");
      throw new RuntimeException(e);
    }
   
    BufferedInputStream bufferedDecryptingInputStream = new BufferedInputStream(new CipherInputStream(in, cipher));
   
    return bufferedDecryptingInputStream;
   
  }
View Full Code Here

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];
                    for (int n = 0; -1 != (n = cipherStream.read(buffer));)
                    {
                        output.write(buffer, 0, n);
                    }
                }
                finally
                {
                    cipherStream.close();
                }
            }
            catch (InvalidKeyException e)
            {
                throw new WrappedIOException(e);
View Full Code Here

Examples of javax.crypto.CipherInputStream

    synchronized (lock) {
      ObjectInputStream input = null;

      try {
        input = new ObjectInputStream(
            new CipherInputStream(context.openFileInput(SECRETS_FILE_NAME),
                                  cipher));
        secrets = (ArrayList<Secret>) input.readObject();
      } catch (Exception ex) {
        Log.e(LOG_TAG, "loadSecretsV1", ex);
      } finally {
View Full Code Here

Examples of javax.crypto.CipherInputStream

    if (!Arrays.equals(pair.salt, salt) || pair.rounds != rounds) {
      return null;
    }

    ObjectInputStream oin = new ObjectInputStream(
        new CipherInputStream(input, cipher));
    try {
      return (ArrayList<Secret>) oin.readObject();
    } finally {
      try {if (null != oin) oin.close();} catch (IOException ex) {}
    }
View Full Code Here

Examples of javax.crypto.CipherInputStream

    {
      InputStream is = new FileInputStream(inputFile);
      try
      {
        java.util.zip.ZipInputStream zis = null;
        CipherInputStream cis = null;
       
        // Check whether we need to decrypt the file content:
        if (passCode != null && passCode.length() > 0)
        {
         
          byte[] iv = new byte[IV_LENGTH];
          is.read(iv);

          Cipher cipher = null;
          try
          {
            cipher = getCipher(Cipher.DECRYPT_MODE, passCode, iv);
          }
          catch (GeneralSecurityException gse)
          {
            throw new ManifoldCFException("Could not decrypt configuratiom file: " + gse.getMessage());
          }
          cis = new CipherInputStream(is, cipher);
          zis = new java.util.zip.ZipInputStream(cis);
        }
        else
          zis = new java.util.zip.ZipInputStream(is);

        try
        {
          // Now, work within a transaction.
          database.beginTransaction();
          try
          {
            // Process the entries in the order in which they were recorded.
            int entries = 0;
            while (true)
            {
              java.util.zip.ZipEntry z = zis.getNextEntry();
              // Stop if there are no more entries
              if (z == null)
                break;
              entries++;
              // Get the name of the entry
              String name = z.getName();
              if (name.equals("outputs"))
                outputManager.importConfiguration(zis);
              else if (name.equals("authorities"))
                authManager.importConfiguration(zis);
              else if (name.equals("connections"))
                connManager.importConfiguration(zis);
              else if (name.equals("jobs"))
                jobManager.importConfiguration(zis);
              else
                throw new ManifoldCFException("Configuration file has an entry named '"+name+"' that I do not recognize");
              zis.closeEntry();

            }
            if (entries == 0 && passCode != null && passCode.length() > 0)
              throw new ManifoldCFException("Cannot read configuration file. Please check your passcode and/or SALT value.");
            // All done!!
          }
          catch (ManifoldCFException e)
          {
            database.signalRollback();
            throw e;
          }
          catch (Error e)
          {
            database.signalRollback();
            throw e;
          }
          finally
          {
            database.endTransaction();
          }
        }
        finally
        {
          zis.close();
          if (cis != null) {
            cis.close();
          }
        }
      }
      finally
      {
View Full Code Here

Examples of javax.crypto.CipherInputStream

            throw new NullPointerException("OutputStream argument cannot be null.");
        }

        javax.crypto.Cipher cipher = initNewCipher(cryptMode, keyBytes, iv, true);

        CipherInputStream cis = new CipherInputStream(in, cipher);

        int bufSize = getStreamingBufferSize();
        byte[] buffer = new byte[bufSize];

        int bytesRead;
        try {
            while ((bytesRead = cis.read(buffer)) != -1) {
                out.write(buffer, 0, bytesRead);
            }
        } catch (IOException e) {
            throw new CryptoException(e);
        }
View Full Code Here

Examples of javax.crypto.CipherInputStream

    public Object unmarshal(Exchange exchange, InputStream encryptedStream) throws Exception {
        Object unmarshalled = null;
        if (encryptedStream != null) {
            byte[] iv = getInlinedInitializationVector(exchange, encryptedStream);
            Key key = getKey(exchange);
            CipherInputStream cipherStream = new CipherInputStream(encryptedStream, initializeCipher(DECRYPT_MODE, key, iv));

            ByteArrayOutputStream plaintextStream = new ByteArrayOutputStream(bufferSize);
            HMACAccumulator hmac = getMessageAuthenticationCode(key);
            byte[] buffer = new byte[bufferSize];
            hmac.attachStream(plaintextStream);
            int read;
            while ((read = cipherStream.read(buffer)) >= 0) {
                hmac.decryptUpdate(buffer, read);
            }
            hmac.validate();
            unmarshalled = plaintextStream.toByteArray();
        }
View Full Code Here

Examples of javax.crypto.CipherInputStream

   * @param out
   */
  public void decrypt(InputStream in, OutputStream out) {
    try {
      // Bytes read from in will be decrypted
      in = new CipherInputStream(in, dcipher);

      // Read in the decrypted bytes and write the cleartext to out
      int numRead = 0;
      while ((numRead = in.read(buf)) >= 0) {
        out.write(buf, 0, numRead);
View Full Code Here

Examples of javax.crypto.CipherInputStream

            byte[] iv = new byte[c.getBlockSize()];

            c.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv));

            encStream = new BCPGInputStream(new CipherInputStream(encData.getInputStream(), c));

            if (encData instanceof SymmetricEncIntegrityPacket)
            {
                truncStream = new TruncatedStream(encStream);
View Full Code Here

Examples of javax.crypto.CipherInputStream

               
                byte[]       iv = new byte[c2.getBlockSize()];
               
                c2.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv));

                encStream = new BCPGInputStream(new CipherInputStream(encData.getInputStream(), c2));
               
                if (encData instanceof SymmetricEncIntegrityPacket)
                {
                    truncStream = new TruncatedStream(encStream);
                    encStream = new DigestInputStream(truncStream, MessageDigest.getInstance(PGPUtil.getDigestName(HashAlgorithmTags.SHA1), provider));
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.