Package javax.crypto

Examples of javax.crypto.CipherOutputStream


                    ciphers = new CipherPair(cipherTransformation);
                }
            } catch (GeneralSecurityException e) {
                throw new IOException(e.getMessage(), e);
            }
            out = new CipherOutputStream(out, ciphers.getEncryptor()) {
                boolean closed;
                public void close() throws IOException {
                    if (!closed) {
                        super.close();
                        closed = true;
View Full Code Here


                    ciphers = new CipherPair(cipherTransformation);
                }
            } catch (GeneralSecurityException e) {
                throw new IOException(e.getMessage(), e);
            }
            out = new CipherOutputStream(out, ciphers.getEncryptor()) {
                boolean closed;
                public void close() throws IOException {
                    if (!closed) {
                        super.close();
                        closed = true;
View Full Code Here

   */
  public boolean encrypt (InputStream in, OutputStream out){
    byte[] buffer = new byte[bufferSize];
   
    try{
      OutputStream cout = new CipherOutputStream(out, encryptionCipher);
      int bytesRead = 0;
      while((bytesRead = in.read(buffer)) >= 0)
        cout.write(buffer, 0 , bytesRead);
     
      cout.close();
      in.close();
      out.close();
    }catch(Exception e){
      System.out.println("Error at encrypt: "+e);
    }
View Full Code Here

        /**
         * {@inheritDoc}
         */
        public OutputStream applyFilter(OutputStream out) throws IOException {
            return new CipherOutputStream(out,
                    encryption.initCipher(number, generation));
        }
View Full Code Here

            scKey = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec);
            AlgorithmParameterSpec paramSpec = new PBEParameterSpec(k1, 2);
            Cipher cptFile=Cipher.getInstance(scKey.getAlgorithm());
            cptFile.init(Cipher.ENCRYPT_MODE, scKey, paramSpec);
            FileOutputStream fosOut=new FileOutputStream(fleWrite);
            CipherOutputStream cosOut=new CipherOutputStream(fosOut, cptFile);
            writeXML(cosOut);
            cosOut.flush();
            cosOut.close();
            fosOut.flush();
            fosOut.close();
            return true;
        }
        catch(IOException ex)
View Full Code Here

            scKey = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec);
            AlgorithmParameterSpec paramSpec = new PBEParameterSpec(k1, 2);
            Cipher cptFile=Cipher.getInstance(scKey.getAlgorithm());
            cptFile.init(Cipher.ENCRYPT_MODE, scKey, paramSpec);
            FileOutputStream fosOut=new FileOutputStream(fleWrite);
            CipherOutputStream cosOut=new CipherOutputStream(fosOut, cptFile);
            writeXML(cosOut);
            cosOut.flush();
            cosOut.close();
            fosOut.flush();
            fosOut.close();
            return true;
        }
        catch(IOException ex)
View Full Code Here

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

                 ecipher = Cipher.getInstance(key.getAlgorithm());
                 ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
             } catch (Exception e) {
               throw new Exception("failed to initialize cipher:"+e.toString());
             }
             os = new CipherOutputStream(os,ecipher);
         }

         if (compress)
             os = new GZIPOutputStream(os);
View Full Code Here

         ecipher = Cipher.getInstance(encryptKey.getAlgorithm());
         ecipher.init(Cipher.ENCRYPT_MODE, encryptKey, encryptParamSpec);
       } catch (Exception e) {
         throw new Exception("failed to initialize cipher:"+e.toString());
       }
       os = new CipherOutputStream(os,ecipher);
     }

     if (compress)
       os = new GZIPOutputStream(os);
View Full Code Here

  public void encrypt(OutputStream out)
  {
    // CBC requires an initialization vector
    try {
      cipher.init(Cipher.ENCRYPT_MODE, skeySpec, paramSpec);
      out = new CipherOutputStream(out, cipher);

//      String u = new String(userid +" " +password);
      StringBuffer u = new StringBuffer(1024);
      u.append(string);
      for (int i=u.length(); i<128; i++)
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.