public class PasswordEncryptor extends Object implements Serializable
| Modifier and Type | Method and Description |
|---|---|
static PasswordEncryptor |
getInstance()
Gets the single instance of PasswordService.
|
String |
getRandomPassword(int length)
Gets a random password.
|
String |
getRandomPassword(Optional<Integer> length)
Gets a random password.
|
String |
getRandomSalt(int length)
Gets a random salt string.
|
String |
hashAndHexPassword(String password,
String salt)
Hash and hex password with the given salt.
|
String |
hashAndHexPassword(String password,
String salt,
HashAlgorithm hashAlgorithm,
Charset charset)
Hash and hex the given password with the given salt, hash algorithm and
charset.
|
String |
hashPassword(String password,
String salt,
HashAlgorithm hashAlgorithm,
Charset charset)
Hashes the given password with the given salt, hash algorithm and
charset.
|
boolean |
match(String hashedPassword,
String dbHashedPassword)
Matches the given strings and returns true if they are equal.
|
public static PasswordEncryptor getInstance()
public String getRandomPassword(int length)
length - the lengthpublic String getRandomPassword(Optional<Integer> length)
length - the lengthpublic String getRandomSalt(int length)
length - the lengthpublic String hashAndHexPassword(String password, String salt) throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException
password - the passwordsalt - the saltNoSuchAlgorithmException - is thrown if instantiation of the MessageDigest object fails.UnsupportedEncodingException - is thrown by get the byte array of the private key String
object fails.NoSuchPaddingException - is thrown if instantiation of the cypher object fails.InvalidKeyException - the invalid key exception is thrown if initialization of the
cypher object fails.BadPaddingException - is thrown if Cipher.doFinal(byte[]) fails.IllegalBlockSizeException - is thrown if Cipher.doFinal(byte[]) fails.public String hashAndHexPassword(String password, String salt, HashAlgorithm hashAlgorithm, Charset charset) throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException
password - the passwordsalt - the salthashAlgorithm - the hash algorithmcharset - the charsetNoSuchAlgorithmException - is thrown if instantiation of the MessageDigest object fails.UnsupportedEncodingException - is thrown by get the byte array of the private key String
object fails.NoSuchPaddingException - is thrown if instantiation of the cypher object fails.InvalidKeyException - the invalid key exception is thrown if initialization of the
cypher object fails.BadPaddingException - is thrown if Cipher.doFinal(byte[]) fails.IllegalBlockSizeException - is thrown if Cipher.doFinal(byte[]) fails.public String hashPassword(String password, String salt, HashAlgorithm hashAlgorithm, Charset charset) throws NoSuchAlgorithmException
password - the passwordsalt - the salthashAlgorithm - the hash algorithmcharset - the charsetNoSuchAlgorithmException - the no such algorithm exceptionCopyright © 2015–2016 Alpha Ro Group UG (haftungsbeschrÀngt). All rights reserved.