Closed parlough closed 7 years ago
The salt is automatically generated, see https://github.com/phxql/argon2-jvm/blob/develop/src/main/java/de/mkammerer/argon2/BaseArgon2.java#L70.
Why do you want to set the salt?
If the salt is randomly generated wouldn't verify not work as the resulting hash would be different every time you put in the password. My understanding is you generate a salt randomly once for the user's password and store that with the resulting hash in a database?
The generated hash includes the salt. The verify method extracts the salt from the hash and uses that.
Oh that's a smart way of doing it actually, thank you, I didn't recognize that.
To be honest, I like this approach as well. And yet I am missing a way to provide salt, secret and additional values. I think it would be beneficial to extend Argon2Advanced
with salt providing String returning methods.
What should the returned string contain?
@phxql, I am really sorry - the effect of typing a comment in the middle of the night. I meant salt providing meaning that it would be IMHO beneficial to create a regular hash
method that would accept salt. Preferably secret and additional as well as it improves security by a factor if used properly...
I do not mind the current ref string returned by the method. Just the input params are a problem for me. Especially that I rewrote a native Java version of Argon2 and I would love to use your library for testing as a wrapper for the reference implementation.
Can you please create a new ticket for that? Then I will take a look into it, thanks :)
There is a method in de.mkammerer.argon2.Argon2Advanced#rawHash(int, int, int, char[], java.nio.charset.Charset, byte[])
which accepts a user-provided salt. Is that usable for you?
de.mkammerer.argon2.Argon2Advanced#rawHash(int, int, int, char[], java.nio.charset.Charset, byte[])
is what I currently use. But what I can't easily do with your library is to go from there to the same result as de.mkammerer.argon2.Argon2#hash(int, int, int, char[])
, which gives me a ref string representation. Obviously, I could calculate that on my level, but that defeats the purpose of trying to be inline with reference implementation...
You need to set the salt to use Argon as a PBKDF...
The library serves two use cases:
Neither 1. or 2. mandates that the user provides the salt. In case 1. the library generates the salt. In case 2. the library reads the salt from the hash and uses that.
If you want to use Argon2 as PBKDF, use the de.mkammerer.argon2.Argon2Advanced#rawHash(int, int, int, char[], java.nio.charset.Charset, byte[])
method. It allows you to set the salt. If you want to alter the derived key length (default is 256 bit), use the de.mkammerer.argon2.Argon2Factory#createAdvanced(de.mkammerer.argon2.Argon2Factory.Argon2Types, int, int)
method to create an instance of Argon2Advanced
.
I planned to use Argon2, but I cannot find a way to include a salt. Are you just using a constant one or what? Would it be possible to allow us to include a salt in the hash function?