Class PasswordSalt
- java.lang.Object
-
- com.helger.security.password.salt.PasswordSalt
-
- All Implemented Interfaces:
IPasswordSalt
@Nonnegative @Immutable public final class PasswordSalt extends Object implements IPasswordSalt
Default implementation ofIPasswordSaltusingVerySecureRandom.- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_SALT_BYTESDefault salt byte length is nothing else is specified.
-
Constructor Summary
Constructors Constructor Description PasswordSalt(byte[] aBytes)Constructor with salt bytes.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static PasswordSaltcreateFromStringMaybe(String sSalt)Try to create aPasswordSaltobject from the passed string.static PasswordSaltcreateRandom()static PasswordSaltcreateRandom(int nSaltBytes)Create a new password salt with the provided byte count.booleanequals(Object o)intgetSaltByteCount()byte[]getSaltBytes()StringgetSaltString()inthashCode()StringtoString()
-
-
-
Field Detail
-
DEFAULT_SALT_BYTES
public static final int DEFAULT_SALT_BYTES
Default salt byte length is nothing else is specified.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PasswordSalt
public PasswordSalt(@Nonnull @Nonempty byte[] aBytes)
Constructor with salt bytes.- Parameters:
aBytes- Salt bytes to use. May not benullor empty.
-
-
Method Detail
-
getSaltByteCount
@Nonnegative public int getSaltByteCount()
- Specified by:
getSaltByteCountin interfaceIPasswordSalt- Returns:
- The number of salt bytes used. Always > 0.
-
getSaltBytes
@Nonnull @Nonempty @ReturnsMutableCopy public byte[] getSaltBytes()
- Specified by:
getSaltBytesin interfaceIPasswordSalt- Returns:
- A copy of the pure salt bytes. Never
nullnor empty.
-
getSaltString
@Nonnull @Nonempty public String getSaltString()
- Specified by:
getSaltStringin interfaceIPasswordSalt- Returns:
- The salt bytes in a string representation for easy serialization.
Never
nullnor empty.
-
createRandom
@Nonnull public static PasswordSalt createRandom()
- Returns:
- A new password salt with the default length of 32 and random bytes.
- Since:
- 10.1.4
-
createRandom
@Nonnull public static PasswordSalt createRandom(@Nonnegative int nSaltBytes)
Create a new password salt with the provided byte count.- Parameters:
nSaltBytes- The number of salt bytes to use. Must be > 0.- Returns:
- the new salt object
- Since:
- 10.1.4
-
createFromStringMaybe
@Nullable public static PasswordSalt createFromStringMaybe(@Nullable String sSalt)
Try to create aPasswordSaltobject from the passed string. First the string is hex decoded into a byte array and this is the password salt.- Parameters:
sSalt- The string to be used. May benull.- Returns:
nullif the passed salt string isnullor empty.- Throws:
IllegalArgumentException- if the passed salt string cannot be hex decoded.
-
-