Interface PwHash.Lazy

All Known Implementing Classes:
LazySodium, LazySodiumJava
Enclosing interface:
PwHash

public static interface PwHash.Lazy
  • 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 between PwHash.BYTES_MIN and PwHash.BYTES_MAX
      password - The password to hash.
      salt - A salt to use with the hash, generated randomly.
      opsLimit - The number of cycles to perform whilst hashing. Between PwHash.OPSLIMIT_MIN and PwHash.OPSLIMIT_MAX.
      memLimit - The amount of memory to use. Between PwHash.MEMLIMIT_MIN and PwHash.MEMLIMIT_MAX.
      alg - The algorithm to use. Defaults to PwHash.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 algorithm PwHash.Alg.
      Parameters:
      password - The password string to hash.
      opsLimit - The number of cycles to perform whilst hashing. Between PwHash.OPSLIMIT_MIN and PwHash.OPSLIMIT_MAX.
      memLimit - The amount of memory to use. Between PwHash.MEMLIMIT_MIN and PwHash.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 algorithm PwHash.Alg.
      Parameters:
      password - The password string to hash.
      opsLimit - The number of cycles to perform whilst hashing. Between PwHash.OPSLIMIT_MIN and PwHash.OPSLIMIT_MAX.
      memLimit - The amount of memory to use. Between PwHash.MEMLIMIT_MIN and PwHash.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(String hash, 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 hexadecimal Helpers.Lazy.sodiumBin2Hex(byte[]).
      password - The password.
      Returns:
      True if the password 'unlocks' the hash.