Package javax.crypto

Examples of javax.crypto.CipherInputStream


    }
  }

  public Object read (Kryo kryo, Input input, Class type) {
    Cipher cipher = getCipher(Cipher.DECRYPT_MODE);
    CipherInputStream cipherInput = new CipherInputStream(input, cipher);
    return kryo.readObject(new Input(cipherInput, 256), type, serializer);
  }
View Full Code Here


        if (file.exists())
        {
            final Cipher cipher = getCipher(Cipher.DECRYPT_MODE, main
                    .getConfig().getString("login.encryptionKey"));
            final DataInputStream in = new DataInputStream(
                    new CipherInputStream(new FileInputStream(file), cipher));
            storedUsername = in.readUTF();
            storedPassword = in.readUTF();
           
            in.close();
        }
View Full Code Here

      catch(Exception e)
      {
         e.printStackTrace();
         throw new IOException("Failed to init cipher: "+e.getMessage());
      }
      CipherInputStream cis = new CipherInputStream(is, cipher);
      return cis;
   }
View Full Code Here

    {
      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("mappings"))
                mappingManager.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

    ByteArrayOutputStream out = new ByteArrayOutputStream(1024 + 32);

    Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7");

    cipher.init(Cipher.DECRYPT_MODE, key);
    CipherInputStream in = new CipherInputStream(inStream, cipher);

    byte[] b = new byte[2048];
    int n;
    while ((n = in.read(b)) != -1)
      if (n > 0)
        out.write(b, 0, n);

    in.close();

    byte[] plaintxt = out.toByteArray();
    harness.check(Arrays.equals(plaintxt, PLAINTEXT), "Plain text MUST match");
  }
View Full Code Here

                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

  {
    try {
      Cipher cipher = initCipher(cookie, Cipher.DECRYPT_MODE);

      ByteArrayInputStream is = new ByteArrayInputStream(encData);
      CipherInputStream cIn = new CipherInputStream(is, cipher);

      Hessian2Input in = new Hessian2Input(cIn);

      Object obj = in.readObject();

      if (! (obj instanceof SelfEncryptedCookie))
        throw new SecurityException(L.l("SelfEncryptedCookie[] is invalid because it does not correctly decrypt"));

      SelfEncryptedCookie cookieObj = (SelfEncryptedCookie) obj;

      in.close();
      cIn.close();
      is.close();

      return cookieObj;
    } catch (SecurityException e) {
      throw e;
View Full Code Here

    public InputStream getDataStream(DirectoryNode dir) throws IOException {
        DocumentInputStream dis = dir.createDocumentInputStream("EncryptedPackage");

        _length = dis.readLong();

        return new BoundedInputStream(new CipherInputStream(dis, getCipher(getSecretKey())), _length);
    }
View Full Code Here

    } 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

                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

TOP

Related Classes of javax.crypto.CipherInputStream

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.