Package org.h2.security
Class SHA256
- java.lang.Object
-
- org.h2.security.SHA256
-
public class SHA256 extends java.lang.Object
This class implements the cryptographic hash function SHA-256.
-
-
Constructor Summary
Constructors Modifier Constructor Description private
SHA256()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]
getHash(byte[] data, boolean nullData)
Calculate the hash code for the given data.static byte[]
getHashWithSalt(byte[] data, byte[] salt)
Calculate the hash code by using the given salt.static byte[]
getHMAC(byte[] key, byte[] message)
Calculate the hash-based message authentication code.static byte[]
getKeyPasswordHash(java.lang.String userName, char[] password)
Calculate the hash of a password by prepending the user name and a '@' character.static byte[]
getPBKDF2(byte[] password, byte[] salt, int iterations, int resultLen)
Calculate the hash using the password-based key derivation function 2.private static javax.crypto.Mac
initMac(byte[] key)
-
-
-
Method Detail
-
getHashWithSalt
public static 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 hashsalt
- the salt to use- Returns:
- the hash code
-
getKeyPasswordHash
public static 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 namepassword
- the password- Returns:
- the hash code
-
getHMAC
public static byte[] getHMAC(byte[] key, byte[] message)
Calculate the hash-based message authentication code.- Parameters:
key
- the keymessage
- the message- Returns:
- the hash
-
initMac
private static javax.crypto.Mac initMac(byte[] key)
-
getPBKDF2
public static byte[] getPBKDF2(byte[] password, byte[] salt, int iterations, int resultLen)
Calculate the hash using the password-based key derivation function 2.- Parameters:
password
- the passwordsalt
- the saltiterations
- the number of iterationsresultLen
- the number of bytes in the result- Returns:
- the result
-
getHash
public static byte[] getHash(byte[] data, boolean nullData)
Calculate the hash code for the given data.- Parameters:
data
- the data to hashnullData
- if the data should be filled with zeros after calculating the hash code- Returns:
- the hash code
-
-