Class Salt
- java.lang.Object
-
- de.uplanet.security.Salt
-
@Scriptable public final class Salt extends Object
Used to create cryptographically secure random strings that can be used as salt values.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_SALT_LENGTH
The default length of a salt string in bytes (16).
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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[]
getBinary()
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[]
toBinary(String p_strHex)
Convert the given hex string to bytes.static String
toHex(byte[] p_buf)
Convert the given bytes to a hex-encoded string.
-
-
-
Field Detail
-
DEFAULT_SALT_LENGTH
public static final int DEFAULT_SALT_LENGTH
The default length of a salt string in bytes (16).- See Also:
- Constant Field Values
-
-
Method Detail
-
get
public static String 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()
-
getBinary
public static byte[] getBinary()
Create cryptographically secure salt value of thedefault length
in bytes.- Returns:
- The salt value.
- See Also:
getBinary(int)
-
get
public static String get(int p_iLen)
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
public static String get(byte[] p_key, int p_iLen)
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
public static String toHex(byte[] p_buf)
Convert the given bytes to a hex-encoded string.- Parameters:
p_buf
- The bytes to convert- Returns:
- The hex-encoded bytes.
-
toBinary
public static byte[] toBinary(String p_strHex)
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.
-
-