Examples of CipherOutputStream


Examples of javax.crypto.CipherOutputStream

  public static void encryptFile(File originalFile, File encryptedFile, String password, String type) throws NoSuchAlgorithmException, NoSuchPaddingException {

    YProgressWindowRepeat y = new YProgressWindowRepeat(I18N.t("Verschlüssle " + originalFile.getName()), "lock");

    FileInputStream in = null;
    CipherOutputStream out = null;
    try {
      // set basics
      Cipher cipher = Cipher.getInstance(type);
      SecretKey key = new SecretKeySpec(password.getBytes(), type);
      cipher.init(Cipher.ENCRYPT_MODE, key);

      // do it
      in = new FileInputStream(originalFile);
      out = new CipherOutputStream(new FileOutputStream(encryptedFile), cipher);
      byte[] byteBuffer = new byte[1024];
      for (int n; (n = in.read(byteBuffer)) != -1; out.write(byteBuffer, 0, n)) {
        ;
      }
      in.close();
      out.close();
      // new File(originalFile).delete();
    } catch (Throwable t) {
      YEx.warn("Can not encrypt File " + originalFile + " to " + encryptedFile, t);
    } finally {
      // close it
      try {
        if (in != null) {
          in.close();
        }
      } catch (IOException e) {
      }
      // close it
      try {
        if (out != null) {
          out.close();
        }
      } catch (IOException e) {
      }
    }
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 org.bouncycastle.crypto.io.CipherOutputStream

            }
        }

        public OutputStream getOutputStream(OutputStream out)
        {
            return new CipherOutputStream(out, c);
        }
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.