Top Description Constructors Methods
org.h2.security

public Class SHA256

extends Object
Class Inheritance
Static Imports
org.h2.util.Bits.INT_VH_BE

This class implements the cryptographic hash function SHA-256.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static byte[]

Returns:

the hash code
getHash
(byte[]
the data to hash
data
,
boolean
if the data should be filled with zeros after calculating the hash code
nullData
)

Calculate the hash code for the given data.

public static byte[]

Returns:

the hash code
getHashWithSalt
(byte[]
the data to hash
data
,
byte[]
the salt to use
salt
)

Calculate the hash code by using the given salt.

public static byte[]

Returns:

the hash
getHMAC
(byte[]
the key
key
,
byte[]
the message
message
)

Calculate the hash-based message authentication code.

public static byte[]

Returns:

the hash code
getKeyPasswordHash
(String
the user name
userName
,
char[]
the password
password
)

Calculate the hash of a password by prepending the user name and a '@' character.

public static byte[]

Returns:

the result
getPBKDF2
(byte[]
the password
password
,
byte[]
the salt
salt
,
int
the number of iterations
iterations
,
int
the number of bytes in the result
resultLen
)

Calculate the hash using the password-based key derivation function 2.

private static Mac
initMac(byte[] key)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

SHA256back to summary
private SHA256()

Method Detail

getHashback to summary
public static byte[] getHash(byte[] data, boolean nullData)

Calculate the hash code for the given data.

Parameters
data:byte[]

the data to hash

nullData:boolean

if the data should be filled with zeros after calculating the hash code

Returns:byte[]

the hash code

getHashWithSaltback to summary
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:byte[]

the data to hash

salt:byte[]

the salt to use

Returns:byte[]

the hash code

getHMACback to summary
public static byte[] getHMAC(byte[] key, byte[] message)

Calculate the hash-based message authentication code.

Parameters
key:byte[]

the key

message:byte[]

the message

Returns:byte[]

the hash

getKeyPasswordHashback to summary
public static byte[] getKeyPasswordHash(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:String

the user name

password:char[]

the password

Returns:byte[]

the hash code

getPBKDF2back to summary
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:byte[]

the password

salt:byte[]

the salt

iterations:int

the number of iterations

resultLen:int

the number of bytes in the result

Returns:byte[]

the result

initMacback to summary
private static Mac initMac(byte[] key)