Examples of CipherOutputStream


Examples of javax.crypto.CipherOutputStream

    output.write(SIGNATURE);
    output.write(salt.length);
    output.write(salt);
    output.write(rounds);
    ObjectOutputStream oout = new ObjectOutputStream(
        new CipherOutputStream(output, cipher));
    try {
      oout.writeObject(secrets);
    } finally {
      try {if (null != oout) oout.close();} catch (IOException ex) {}
    }
View Full Code Here

Examples of javax.crypto.CipherOutputStream

     
      try
      {
       
        java.util.zip.ZipOutputStream zos = null;
        CipherOutputStream cos = null;
       
        // Check whether we need to encrypt the file content:
        if (passCode != null && passCode.length() > 0)
        {
         
          // Write IV as a prefix:
          SecureRandom random = new SecureRandom();
          byte[] iv = new byte[IV_LENGTH];
          random.nextBytes(iv);
          os.write(iv);
          os.flush();
         
          Cipher cipher = null;
          try
          {
            cipher = getCipher(Cipher.ENCRYPT_MODE, passCode, iv);
          }
          catch (GeneralSecurityException gse)
          {
            throw new ManifoldCFException("Could not encrypt configuratiom file: " + gse.getMessage());
          }
         
          cos = new CipherOutputStream(os, cipher);
          zos = new java.util.zip.ZipOutputStream(cos);
        }
        else
          zos = new java.util.zip.ZipOutputStream(os);
        try
        {
          // Now, work within a transaction.
          database.beginTransaction();
          try
          {
            // At the outermost level, I've decided that the best structure is to have a zipentry for each
            // manager.  Each manager must manage its own data as a binary blob, including any format versioning information,
            // This guarantees flexibility for the future.

            // The zipentries must be written in an order that permits their proper restoration.  The "lowest level" is thus
            // written first, which yields the order: authority connections, repository connections, jobs
            java.util.zip.ZipEntry outputEntry = new java.util.zip.ZipEntry("outputs");
            zos.putNextEntry(outputEntry);
            outputManager.exportConfiguration(zos);
            zos.closeEntry();

            java.util.zip.ZipEntry authEntry = new java.util.zip.ZipEntry("authorities");
            zos.putNextEntry(authEntry);
            authManager.exportConfiguration(zos);
            zos.closeEntry();

            java.util.zip.ZipEntry connEntry = new java.util.zip.ZipEntry("connections");
            zos.putNextEntry(connEntry);
            connManager.exportConfiguration(zos);
            zos.closeEntry();

            java.util.zip.ZipEntry jobsEntry = new java.util.zip.ZipEntry("jobs");
            zos.putNextEntry(jobsEntry);
            jobManager.exportConfiguration(zos);
            zos.closeEntry();

            // All done
          }
          catch (ManifoldCFException e)
          {
            database.signalRollback();
            throw e;
          }
          catch (Error e)
          {
            database.signalRollback();
            throw e;
          }
          finally
          {
            database.endTransaction();
          }
        }
        finally
        {
          zos.close();
          if (cos != null) {
            cos.close();
          }
        }
      }
      finally
      {
View Full Code Here

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

Examples of javax.crypto.CipherOutputStream

      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

Examples of javax.crypto.CipherOutputStream

      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

Examples of javax.crypto.CipherOutputStream

  {
    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

Examples of javax.crypto.CipherOutputStream

     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

Examples of javax.crypto.CipherOutputStream

    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

Examples of javax.crypto.CipherOutputStream

   * @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

Examples of javax.crypto.CipherOutputStream

                    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
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.