Logo
Distributed Genetic Programming Framework
print print

File org.sfc.crypt.CryptographicKey.java

Here you can find all the information about the file org.sfc.crypt.CryptographicKey.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-28 06:34:38
 * Original Filename: org.sfc.crypt.CryptographicKey.java
 * Version          : 1.0.0
 * Last modification: 2006-06-28
 *                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 org.sfc.text.Text;

/**
 * This class encapsulates the immutable data of a cryptographic key.
 *
 * @author Thomas Weise
 */

public class CryptographicKey
  {
/**
 * The key data.
 */

  final byte[]  m_data  ;
  
/**
 * Create a copy of a cryptographic key instance.
 * @param p_key The key to copy from.
 */

  CryptographicKey(final CryptographicKey p_key)
    {
    super();
    this.m_data = p_key.m_data.clone();
    }
  
/**
 * Create a cryptographic key from an array of bytes.
 * @param p_data  The key data of the bytes to be used.
 */

  private CryptographicKey  (final byte[] p_data)
    {
    super();
    this.m_data = p_data;
    }
  
  
/**
 * Create a new key from a string.
 * @param p_data  The string containing the password.
 * @return  A new cryptographic key representing the password data.
 */

  public static final CryptographicKey from_pass_string(final String p_data)
    { 
    byte[]  l_b;
    l_b = Text.string_to_bytes(p_data);
    l_b = add_noise(l_b);
    
    return new CryptographicKey(l_b);
    }
  
/**
 * Add some noise to a key data arry.
 * @param p_data    The key data array.
 * @return  An key data array with more noise.
 */

  private static  final byte[]  add_noise (final byte[] p_data)
    {
    int[]   l_c;
    byte[]  l_b;
    byte    l_x;
    int     l_i, l_ma, l_s, l_v, l_l;
    
    l_c = new int[256];
    l_l = p_data.length;
    for(l_i = (l_l-1); l_i >= 0; l_i--)
      {
      l_c[p_data[l_i] & 0xff]++;
      }
        
    l_s = l_ma = l_c[0];
    for(l_i = 1; l_i < 256; l_i++)
      {
      l_v = l_c[l_i];
      if(l_v > l_ma) l_ma = l_v;
      l_s += l_v;
      }
    
    l_i = (l_ma << 8);
    
    if(l_i <= l_l) return p_data;
    
    l_b = new byte[l_i];
    System.arraycopy(p_data, 0, l_b, 0, l_l);
    
    for(; l_l < l_i; l_l++)
      {
      for(l_s = ((l_s+1)&255); (l_c[l_s]++) >= l_ma; l_s = ((l_s+1)&255))
        {
        //
        }
      l_b[l_l] = ((byte)l_s);
      }
    
    for(l_ma = l_l; l_ma > 0; l_ma--)
      {
      for(l_i = (l_l-1); l_i >= 0; l_i--)
        {
        l_x = l_b[l_i];
        
        if(l_x != 0) l_s *= l_x;
        else         l_s++;
        l_s -= l_b[l_s & 255] + l_ma;
        
        l_v = (l_s & 255);
        
        l_b[l_i] = l_b[l_v];
        l_b[l_v] = l_x;
        }
      }
    
    return l_b;
    }
  
/**
 * Obtain the size of this key.
 * @return  The count of bytes contained in this key.
 */

  public  final int get_size  ()
    {
    return this.m_data.length;
    }
  
/**
 * Obtain a byte from the key.
 * @param   p_index The index of the wanted byte.
 * @return  The byte at that index.
 */

  public  final byte  get(final int p_index)
    {
    return this.m_data[p_index];
    }
  }

File Information:

file name:CryptographicKey.java
package:org.sfc.crypt
qualified name:org.sfc.crypt.CryptographicKey.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/sfc/crypt/CryptographicKey.java
size:3.913 KB (4007 B)
uploaded: 2018-01-07 12:03:36 GMT+0000
last update: 2006-06-30 03:50:50 GMT+0000
last access: 2018-04-21 07:41:20 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 2018-01-07 12:03:34 GMT+0000 served at 2018-04-21 07:41:20 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo