Interface PwHash.Lazy
- All Known Implementing Classes:
LazySodium,LazySodiumJava
- Enclosing interface:
- PwHash
public static interface PwHash.Lazy
-
Method Summary
Modifier and TypeMethodDescriptioncryptoPwHash(String password, int cryptoPwHashLen, byte[] salt, long opsLimit, com.sun.jna.NativeLong memLimit, PwHash.Alg alg) Hashes a given password.cryptoPwHashStr(String password, long opsLimit, com.sun.jna.NativeLong memLimit) The most minimal way of hashing a given password.cryptoPwHashStrRemoveNulls(String password, long opsLimit, com.sun.jna.NativeLong memLimit) Hashes a string and removes all the null bytes.booleancryptoPwHashStrVerify(String hash, String password) Verifies a password.
-
Method Details
-
cryptoPwHash
String cryptoPwHash(String password, int cryptoPwHashLen, byte[] salt, long opsLimit, com.sun.jna.NativeLong memLimit, PwHash.Alg alg) throws SodiumException Hashes a given password.- Parameters:
cryptoPwHashLen- The hash size that you want. Anything betweenPwHash.BYTES_MINandPwHash.BYTES_MAXpassword- The password to hash.salt- A salt to use with the hash, generated randomly.opsLimit- The number of cycles to perform whilst hashing. BetweenPwHash.OPSLIMIT_MINandPwHash.OPSLIMIT_MAX.memLimit- The amount of memory to use. BetweenPwHash.MEMLIMIT_MINandPwHash.MEMLIMIT_MAX.alg- The algorithm to use. Defaults toPwHash.Alg.PWHASH_ALG_ARGON2ID13.- Returns:
- A hash of the password in bytes.
- Throws:
SodiumException- If the password is too short or the opsLimit is not correct.
-
cryptoPwHashStr
String cryptoPwHashStr(String password, long opsLimit, com.sun.jna.NativeLong memLimit) throws SodiumException The most minimal way of hashing a given password. We auto-generate the salt and use the default hashing algorithmPwHash.Alg.- Parameters:
password- The password string to hash.opsLimit- The number of cycles to perform whilst hashing. BetweenPwHash.OPSLIMIT_MINandPwHash.OPSLIMIT_MAX.memLimit- The amount of memory to use. BetweenPwHash.MEMLIMIT_MINandPwHash.MEMLIMIT_MAX.- Returns:
- The hashed password
- Throws:
SodiumException- If the password could not be hashed.
-
cryptoPwHashStrRemoveNulls
String cryptoPwHashStrRemoveNulls(String password, long opsLimit, com.sun.jna.NativeLong memLimit) throws SodiumException Hashes a string and removes all the null bytes. Uses the hashing algorithmPwHash.Alg.- Parameters:
password- The password string to hash.opsLimit- The number of cycles to perform whilst hashing. BetweenPwHash.OPSLIMIT_MINandPwHash.OPSLIMIT_MAX.memLimit- The amount of memory to use. BetweenPwHash.MEMLIMIT_MINandPwHash.MEMLIMIT_MAX.- Returns:
- The hash without null bytes at the end. WARNING: when verifying please remember to ADD a null byte to the end!
- Throws:
SodiumException- If the password could not be hashed.
-
cryptoPwHashStrVerify
Verifies a password. Good news: this function automatically adds a null byte to the end which is required for the native underlying function to work.- Parameters:
hash- The hash. Must be hexadecimalHelpers.Lazy.sodiumBin2Hex(byte[]).password- The password.- Returns:
- True if the password 'unlocks' the hash.
-