Examples of CipherInputStream


Examples of javax.crypto.CipherInputStream

  public static void decryptFile(File encryptedFile, File decryptedFile, String password, String type) throws NoSuchAlgorithmException,
      NoSuchPaddingException {

    YProgressWindowRepeat y = new YProgressWindowRepeat(I18N.t("Entschlüssle " + encryptedFile.getName()), "unlock");

    CipherInputStream in = null;
    OutputStream out = null;
    try {
      // set basics
      Cipher cipher = Cipher.getInstance(type);
      SecretKey key = new SecretKeySpec(password.getBytes(), type);
      cipher.init(Cipher.DECRYPT_MODE, key);
      // do it
      in = new CipherInputStream(new FileInputStream(encryptedFile), cipher);
      out = new FileOutputStream(decryptedFile);
      byte[] byteBuffer = new byte[1024];
      for (int n; (n = in.read(byteBuffer)) != -1; out.write(byteBuffer, 0, n)) {
        ;
      }
      in.close();
      out.close();
      // new File(encryptedFile).delete();
    } catch (Throwable t) {
      YEx.warn("Can not decrypt File " + encryptedFile + " to " + decryptedFile, t);
    } finally {
      // close it
      try {
        if (in != null) {
          in.close();
        }
      } catch (IOException e) {
      }
      // close it
      try {
View Full Code Here

Examples of javax.crypto.CipherInputStream

                    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

Examples of org.bouncycastle.crypto.io.CipherInputStream

                  rng.nextBytes(key);
                  rng.nextBytes(iv);
                  AESFastEngine e = new AESFastEngine();
                  SICBlockCipher ctr = new SICBlockCipher(e);
                  ctr.init(true, new ParametersWithIV(new KeyParameter(key),iv));
                  cis = new CipherInputStream(zis, new BufferedBlockCipher(ctr));
                  cisCounter = 0;
              }
              read = cis.read(buffer, 0, ((remaining > BUFFER_SIZE) || (remaining == -1)) ? BUFFER_SIZE : (int) remaining);
              cisCounter += read;
          }
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.