CIC iSign Version 1.2

InkTools
Class CicHash

java.lang.Object
  |
  +--InkTools.CicHash

public class CicHash
extends java.lang.Object

CIC's implementation of the Secure Hash Algorithm (SHA) to produce a message digest. The message digest or hashing is used for binding, creating 'digital signatures' and other cryptographic applications in general.

Binding a signature to a document can be done through generating a common message digest from the document and the signature (see CicDoodle.streamOut). Then the document, signature and message digest can be stored into one object or as several objects. If the document or signature gets manipulated, the resulting message digest would change. To verify if a document with the attached signature is unaltered, create a new message digest of both and then compare it to the saved original message digest. If they match, document and signature are unaltered. If the digest are different, it can be assumed that these are manipulated.

To secure that the original message digest gets not replaced with a message digest of the altered document/signature, the message digest should be encrypted and than stored. Use the 'getEncryptedHashValue' and 'decryptHashValue' for that purpose.

Version:
1.0
Author:
CIC

Constructor Summary
CicHash()
          Constructs a Cichash object.
CicHash(byte[] buffer)
          Constructor for a whole hash session.
 
Method Summary
 void addHash(byte[] buf)
          Adds a byte array to the current hashing session
 void addHash(java.lang.String str)
          Adds a String to the current hashing session.
 boolean compareHash(byte[] hash1, byte[] hash2)
          compares 2 CIC's SHS 20 byte long hash arrays
 boolean compareHash(int[] hash1, int[] hash2)
          compares 2 CIC's SHS 5 integer long hash arrays
 java.lang.String createEncryptionKeyFromPhrase(java.lang.String phrase, int keyLength)
          Creates a 8 character or 24 character string from a phrase with any length.
 int[] decryptHashValue(int[] encHash, java.lang.String key)
          Decrypts an priviously encrypted hash value and returns the original hash value in an array of 5 integer.
 void finishHash()
          Finishs the current hashing session.
 int[] getEncryptedHashValue(java.lang.String key)
          Encrypts the hashing value and returns it in an array of 8 intergers.
 int[] getHashValue()
          Returns the hashing value from the last hashing session in an array of 5 integers.
 byte[] getHashValueBytes()
          Returns the hashing value from the last hashing session in an array od 20 bytes.
 void initHash()
          Initializes a new hashing session.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CicHash

public CicHash()
Constructs a Cichash object.


CicHash

public CicHash(byte[] buffer)
Constructor for a whole hash session. This doeas perform a initHash(), addHash() and finishHash() in one shot. Call 'getHashValue' or 'getEncryptedHashValue' to get the result.

Parameters:
buffer - the byte array from which to calculate the hash value
Method Detail

initHash

public void initHash()
Initializes a new hashing session.


addHash

public void addHash(java.lang.String str)
Adds a String to the current hashing session.

Parameters:
str - the string to be added to the current hashing session

addHash

public void addHash(byte[] buf)
Adds a byte array to the current hashing session

Parameters:
buf - Byte buffer to be added to the current hashing session.

finishHash

public void finishHash()
Finishs the current hashing session.


getHashValue

public int[] getHashValue()
Returns the hashing value from the last hashing session in an array of 5 integers.

Returns:
an array with 5 integers representing the hashing value

getHashValueBytes

public byte[] getHashValueBytes()
Returns the hashing value from the last hashing session in an array od 20 bytes.

Returns:
an array with 20 bytes representing the hashing value

getEncryptedHashValue

public int[] getEncryptedHashValue(java.lang.String key)
Encrypts the hashing value and returns it in an array of 8 intergers. The original hash value is 5 integer long, the used DES encryption algorithm cretates an 8 integer array from it. This value can be used as an input to the decryptHashValue function.

Parameters:
key - the encryption key used to encrypt the hash value, must be 8 characters long
Returns:
an array of 8 intergers conatining the encrypted hash value or null if an error occured

decryptHashValue

public int[] decryptHashValue(int[] encHash,
                              java.lang.String key)
Decrypts an priviously encrypted hash value and returns the original hash value in an array of 5 integer. The encrypted hash value is assumed as to be 8 intergers long.

Parameters:
encHash - an interger array with the encryped hash value
key - the key to decrypt the hash value
Returns:
an array of 5 intergers containing the hash value or null if an error occured

compareHash

public boolean compareHash(int[] hash1,
                           int[] hash2)
compares 2 CIC's SHS 5 integer long hash arrays

Parameters:
hash1 - 5 interger hash array
hash2 - 5 interger hash array
Returns:
treu if hash is identical, otherwise false

compareHash

public boolean compareHash(byte[] hash1,
                           byte[] hash2)
compares 2 CIC's SHS 20 byte long hash arrays

Parameters:
hash1 - 20 byte hash array
hash2 - 20 byte hash array
Returns:
true if hash is identical, otherwise false

createEncryptionKeyFromPhrase

public java.lang.String createEncryptionKeyFromPhrase(java.lang.String phrase,
                                                      int keyLength)
Creates a 8 character or 24 character string from a phrase with any length. This function is useful for using encryption: instead of asking an exact 8 chars or 24 chars key from the user, any phrase from the user can be used for the encryption through building the hash value of it. This can be used as en encryption key for CIC's FAST, DES, DES40 and TRIPLEDES encryption.

Parameters:
phrase - a string from which an encryption key should be build from
keyLength - 8 for 8 byte key, 24 for 24 byte key
Returns:
an 8 or 24 character long encryption key string

CIC iSign Version 1.2