Logo
Distributed Genetic Programming Framework
print print

File org.sfc.crypt.EncryptStream.java

Here you can find all the information about the file org.sfc.crypt.EncryptStream.java. You may explore it here or download it onto your local disk.
/*
 * Copyright (c) 2006 Thomas Weise
 * 
 * E-Mail           : tweise@gmx.de
 * Creation Date    : 2006-06-29 07:30:53
 * Original Filename: org.sfc.crypt.EncryptStream.java
 * Version          : 1.0.0
 * Last modification: 2006-06-29
 *                by: Thomas Weise
 * 
 * License          : GNU LESSER GENERAL PUBLIC LICENSE
 *                    Version 2.1, February 1999
 *                    You should have received a copy of this license along
 *                    with this library; if not, write to the Free Software
 *                    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *                    MA 02111-1307, USA or download the license under
 *                    http://www.gnu.org/copyleft/lesser.html.
 *                    
 * Warranty         : This software is provided "as is" without any
 *                    warranty; without even the implied warranty of
 *                    merchantability or fitness for a particular purpose.
 *                    See the Gnu Lesser General Public License for more
 *                    details.
 */

 
package org.sfc.crypt;

import java.io.OutputStream;

import org.sfc.io.block.BlockOutputStream;
import org.sfc.io.block.IBlockHandler;

/**
 * A stream that automatically encrypts all the data written to it.
 *
 * @author Thomas Weise
 */

public final  class EncryptStream extends BlockOutputStream
  {
/**
 * Create a new encrypted output stream.
 * @param p_out         The output stream to write to.
 * @param p_block_size  The block size to be used for writing. If this is
 *                      <code>-1</code>, the length of the cryptographic
 *                      key assigned to the cryptographic algorithm will
 *                      be used.
 * @param p_algorithm   The cryptographic algorithm chain to be used for
 *                      encryption.
 */

  public  EncryptStream (final OutputStream           p_out,
                         final int                    p_block_size,
                         final CryptographicAlgorithm p_algorithm)
    {
    super(p_out,
         ((p_block_size > 0) ? p_block_size : p_algorithm.m_data.length),
         new EncBlockHandler(p_algorithm));
    }
  
  
/**
 * The internal block handler.
 *
 * @author Thomas Weise
 */

  private static  final class EncBlockHandler implements  IBlockHandler
    {
/**
 * The internally used cryptographic algorithm.
 */

    private final CryptographicAlgorithm  m_algorithm ;
    
/**
 * Create a new internal block handler.
 * @param p_algorithm   The cryptographic algorithm to be used.
 */

    EncBlockHandler(final CryptographicAlgorithm p_algorithm)
      {
      super();
      this.m_algorithm = p_algorithm;
      }
    
/**
 * This method will be called directly before a block is written to the
 * output or before it will be available for the input.
 * @param p_block The block to be written or read. You may modify its
 *                contents.
 */

    public  final void  on_block  (final byte[] p_block)
      {
      CryptographicAlgorithm  p_a;
      
      for(p_a = this.m_algorithm; p_a != null; p_a = p_a.m_next)
        {
        p_a.encrypt(p_block, p_a.m_data);
        }
      }
    }
  }

File Information:

file name:EncryptStream.java
package:org.sfc.crypt
qualified name:org.sfc.crypt.EncryptStream.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/sfc/crypt/EncryptStream.java
size:3.221 KB (3299 B)
uploaded: 2015-07-22 04:11:11 GMT+0000
last update: 2006-06-30 05:33:47 GMT+0000
last access: 2018-01-22 04:06:40 GMT+0000

statistics online since 2006-01-02.   RSS Feed
Contact us by sending an email to tweise@gmx.de to receive further information, to report errors, or to join our project.
All content on this site (http://dgpf.sourceforge.net/) is LGPL-licensed.
http://dgpf.sourceforge.net/scripts/source/source.php last modified at 2015-07-22 04:10:53 GMT+0000 served at 2018-01-22 04:06:40 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo