Package javax.crypto

Examples of javax.crypto.CipherOutputStream


                characterEventGeneratorOutputStream = new CharacterEventGeneratorOutputStream();
                Base64OutputStream base64EncoderStream =
                        new Base64OutputStream(characterEventGeneratorOutputStream, true, 0, null);
                base64EncoderStream.write(iv);

                OutputStream outputStream = new CipherOutputStream(base64EncoderStream, symmetricCipher);
                outputStream = applyTransforms(outputStream);
                //the trimmer output stream is needed to strip away the dummy wrapping element which must be added
                cipherOutputStream = new TrimmerOutputStream(outputStream, 8192 * 10, 3, 4);

                //we create a new StAX writer for optimized namespace writing.
View Full Code Here


      iv[i] = 0;
    cipherOut.init(Cipher.ENCRYPT_MODE, secretKey, new IvParameterSpec(iv));

    // bkSize è un numero intero di blocchi vicino alle dimensioni di BUFFER_SIZE
    int bkSize = (BUFFER_SIZE / cipherOut.getBlockSize()) * cipherOut.getBlockSize();
    CipherOutputStream cout = new CipherOutputStream(out, cipherOut);

    if(lol != null)
      lol.resetUI();

    int n;
    long count = 0;
    byte[] buffer = new byte[bkSize];
    while((n = in.read(buffer)) > 0)
    {
      cout.write(buffer, 0, n);
      count += n;

      if(lol != null)
        lol.updateUI(count, total);
    }

    if(lol != null)
      lol.completeUI(total);

    cout.flush();
    cout.close();
  }
View Full Code Here

      iv[i] = 0;
    cipherOut.init(Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(iv));

    // bkSize è un numero intero di blocchi vicino alle dimensioni di BUFFER_SIZE
    int bkSize = (BUFFER_SIZE / cipherOut.getBlockSize()) * cipherOut.getBlockSize();
    CipherOutputStream cout = new CipherOutputStream(out, cipherOut);

    if(lol != null)
      lol.resetUI();

    int n;
    long count = 0;
    byte[] buffer = new byte[bkSize];
    while((n = in.read(buffer)) > 0)
    {
      cout.write(buffer, 0, n);
      count += n;

      if(lol != null)
        lol.updateUI(count, total);
    }

    if(lol != null)
      lol.completeUI(total);

    cout.flush();
    cout.close();
  }
View Full Code Here

  {
    Cipher rsa = Cipher.getInstance(PKCS11_RSA, CryptoBaseEngine.SUN_PKCS11_PROVIDER_NAME);
    rsa.init(Cipher.ENCRYPT_MODE, pk);
    int bkSize = rsa.getBlockSize();

    OutputStream os = new CipherOutputStream(out, rsa);

    if(lol != null)
      lol.resetUI();

    int n;
    long count = 0;
    byte[] buffer = new byte[bkSize];
    while((n = in.read(buffer)) > 0)
    {
      os.write(buffer, 0, n);
      count += n;

      if(lol != null)
        lol.updateUI(count, total);
    }

    if(lol != null)
      lol.completeUI(total);

    os.flush();
    os.close();
  }
View Full Code Here

     throws Exception
  {
    Cipher rsa = Cipher.getInstance(PKCS11_RSA, CryptoBaseEngine.SUN_PKCS11_PROVIDER_NAME);
    rsa.init(Cipher.DECRYPT_MODE, pk);

    OutputStream os = new CipherOutputStream(out, rsa);

    if(lol != null)
      lol.resetUI();

    int n;
    long count = 0;
    byte[] buffer = new byte[4096];
    while((n = in.read(buffer)) > 0)
    {
      os.write(buffer, 0, n);
      count += n;

      if(lol != null)
        lol.updateUI(count, total);
    }

    if(lol != null)
      lol.completeUI(total);

    os.flush();
    os.close();
  }
View Full Code Here

    public void marshal(Exchange exchange, Object graph, OutputStream outputStream) throws Exception {
        byte[] iv = getInitializationVector(exchange);
        Key key = getKey(exchange);

        CipherOutputStream cipherStream = new CipherOutputStream(outputStream, initializeCipher(ENCRYPT_MODE, key, iv));
        InputStream plaintextStream = ExchangeHelper.convertToMandatoryType(exchange, InputStream.class, graph);
        HMACAccumulator hmac = getMessageAuthenticationCode(key);
        if (plaintextStream != null) {
            inlineInitVector(outputStream, iv);
            byte[] buffer = new byte[bufferSize];
            int read;
            try {
                while ((read = plaintextStream.read(buffer)) > 0) {
                    cipherStream.write(buffer, 0, read);
                    cipherStream.flush();
                    hmac.encryptUpdate(buffer, read);
                }
                // only write if there is data to write (IBM JDK throws exception if no data)
                byte[] mac = hmac.getCalculatedMac();
                if (mac != null && mac.length > 0) {
                    cipherStream.write(mac);
                }
            } finally {
                ObjectHelper.close(cipherStream, "cipher", LOG);
            }
        }
View Full Code Here

   * @param out
   */
  public void encrypt(InputStream in, OutputStream out) {
    try {
      // Bytes written to out will be encrypted
      out = new CipherOutputStream(out, ecipher);

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

                    pOut = new BCPGOutputStream(out, PacketTags.SYMMETRIC_KEY_ENC, buffer);
                }
            }


            OutputStream genOut = cOut = new CipherOutputStream(pOut, c);

            if (withIntegrityPacket)
            {
                String digestName = PGPUtil.getDigestName(HashAlgorithmTags.SHA1);
                MessageDigest digest = MessageDigest.getInstance(digestName, defProvider);
View Full Code Here

  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

            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

TOP

Related Classes of javax.crypto.CipherOutputStream

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.