org.h2.security
Class SHA256

java.lang.Object
  extended by org.h2.security.SHA256

public class SHA256
extends java.lang.Object

This class implements the cryptographic hash function SHA-256.


Constructor Summary
SHA256()
           
 
Method Summary
 byte[] getHash(byte[] data, boolean nullData)
          Calculate the hash code for the given data.
 byte[] getHashWithSalt(byte[] data, byte[] salt)
          Calculate the hash code by using the given salt.
 byte[] getKeyPasswordHash(java.lang.String userName, char[] password)
          Calculate the hash of a password by prepending the user name and a '@' character.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SHA256

public SHA256()
Method Detail

getHashWithSalt

public byte[] getHashWithSalt(byte[] data,
                              byte[] salt)
Calculate the hash code by using the given salt. The salt is appended after the data before the hash code is calculated. After generating the hash code, the data and all internal buffers are filled with zeros to avoid keeping insecure data in memory longer than required (and possibly swapped to disk).

Parameters:
data - the data to hash
salt - the salt to use
Returns:
the hash code

getKeyPasswordHash

public byte[] getKeyPasswordHash(java.lang.String userName,
                                 char[] password)
Calculate the hash of a password by prepending the user name and a '@' character. Both the user name and the password are encoded to a byte array using UTF-16. After generating the hash code, the password array and all internal buffers are filled with zeros to avoid keeping the plain text password in memory longer than required (and possibly swapped to disk).

Parameters:
userName - the user name
password - the password
Returns:
the hash code

getHash

public byte[] getHash(byte[] data,
                      boolean nullData)
Calculate the hash code for the given data.

Parameters:
data - the data to hash
nullData - if the data should be filled with zeros after calculating the hash code
Returns:
the hash code