Package com.goterl.lazysodium.interfaces
Interface PwHash.Lazy
-
- All Known Implementing Classes:
LazySodium,LazySodiumJava
- Enclosing interface:
- PwHash
public static interface PwHash.Lazy
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.StringcryptoPwHash(java.lang.String password, int cryptoPwHashLen, byte[] salt, long opsLimit, com.sun.jna.NativeLong memLimit, PwHash.Alg alg)Hashes a given password.java.lang.StringcryptoPwHashStr(java.lang.String password, long opsLimit, com.sun.jna.NativeLong memLimit)The most minimal way of hashing a given password.java.lang.StringcryptoPwHashStrRemoveNulls(java.lang.String password, long opsLimit, com.sun.jna.NativeLong memLimit)Hashes a string and removes all the null bytes.booleancryptoPwHashStrVerify(java.lang.String hash, java.lang.String password)Verifies a password.
-
-
-
Method Detail
-
cryptoPwHash
java.lang.String cryptoPwHash(java.lang.String password, int cryptoPwHashLen, byte[] salt, long opsLimit, com.sun.jna.NativeLong memLimit, PwHash.Alg alg) throws SodiumExceptionHashes 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
java.lang.String cryptoPwHashStr(java.lang.String password, long opsLimit, com.sun.jna.NativeLong memLimit) throws SodiumExceptionThe 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
java.lang.String cryptoPwHashStrRemoveNulls(java.lang.String password, long opsLimit, com.sun.jna.NativeLong memLimit) throws SodiumExceptionHashes 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
boolean cryptoPwHashStrVerify(java.lang.String hash, java.lang.String password)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.
-
-