Class Salt
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The default length of a salt string in bytes (16). -
Method Summary
Modifier and TypeMethodDescriptionstatic String
get()
Create a cryptographically secure hex-encoded salt value of thedefault length
in bytes.static String
get
(byte[] p_key, int p_iLen) Create a hex-encoded salt value of the given length in bytes.static String
get
(int p_iLen) Create a cryptographically secure hex-encoded salt value of the given length in bytes.static byte[]
Create cryptographically secure salt value of thedefault length
in bytes.static byte[]
getBinary
(byte[] p_key, int p_iLen) Create a salt value of the given length in bytes.static byte[]
getBinary
(int p_iLen) Create a cryptographically secure hex-encoded salt value of the given length in bytes.static byte[]
Convert the given hex string to bytes.static String
toHex
(byte[] p_buf) Convert the given bytes to a hex-encoded string.
-
Field Details
-
DEFAULT_SALT_LENGTH
public static final int DEFAULT_SALT_LENGTHThe default length of a salt string in bytes (16).- See Also:
-
-
Method Details
-
get
Create a cryptographically secure hex-encoded salt value of thedefault length
in bytes.Note that the length of the returned hex-encoded string is twice of the length in bytes.
- Returns:
- The hex-encoded salt value.
- See Also:
-
getBinary
public static byte[] getBinary()Create cryptographically secure salt value of thedefault length
in bytes.- Returns:
- The salt value.
- See Also:
-
get
Create a cryptographically secure hex-encoded salt value of the given length in bytes.Note that the length of the returned hex-encoded string is twice of the length in bytes.
- Parameters:
p_iLen
- The length of the salt value in bytes.- Returns:
- The hex-encoded salt value.
-
getBinary
public static byte[] getBinary(int p_iLen) Create a cryptographically secure hex-encoded salt value of the given length in bytes.- Parameters:
p_iLen
- The length of the salt value in bytes.- Returns:
- The salt value.
-
get
Create a hex-encoded salt value of the given length in bytes.The created salt is only cryptographically secure if the provided key material is cryptographically secure, i.e. contains cryptographically secure random bits.
The derived salt value contains at most 256 bits of entropy.
The given key material cannot be recovered from the generated salt.
Note that the length of the returned hex-encoded string is twice of the length in bytes.
- Parameters:
p_key
- The key material that determines the value of the salt.p_iLen
- The length of the salt value in bytes.- Returns:
- The hex-encoded salt value.
-
getBinary
public static byte[] getBinary(byte[] p_key, int p_iLen) Create a salt value of the given length in bytes.The created salt is only cryptographically secure if the provided key material is cryptographically secure, i.e. contains cryptographically secure random bits.
The derived salt value contains at most 256 bits of entropy.
The given key material cannot be recovered from the generated salt.
- Parameters:
p_key
- The key material that determines the value of the salt.p_iLen
- The length of the salt value in bytes.- Returns:
- The salt value.
-
toHex
Convert the given bytes to a hex-encoded string.- Parameters:
p_buf
- The bytes to convert- Returns:
- The hex-encoded bytes.
-
toBinary
Convert the given hex string to bytes.- Parameters:
p_strHex
- A string of hex-encoded bytes.- Returns:
- The decoded bytes.
- Throws:
IllegalArgumentException
- If the input length is odd or if the input contains non-hexadecimal digits.
-