Closed onkoe closed 1 month ago
The PHC string format implemented by the password-hash
crate deliberately uses a subset of Base64 called "B64", which is defined here:
https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md#b64
The B64 encoding is the standard Base64 encoding (RFC 4648, section 4) except that the padding = signs are omitted, and extra characters (whitespace) are not allowed
The lack of support for padding with =
is intentional and by design/specification.
@tarcieri Thank you for your reply. Would a PR mentioning this in the documentation be accepted?
Yes, although note it is already documented here: https://docs.rs/password-hash/latest/password_hash/enum.Encoding.html#variant.B64
Some additional documentation in other places might be helpful.
It seems that, when creating your own salt and forming it into base64,
password_hash::SaltString
currently does not account for the allowed=
characters in base64 strings.Here's a repro using
argon2
:This example fails with the following:
I believe it is expecting an undocumented invariant to be upheld: any base64 input should have its equal signs removed.
Accordingly, removing them addresses the problem:
You can also use the
encode_b64
constructor onSaltString
, though this feels a bit off for my project. I need these hashes to be deterministic, and I have little control overpassword_hash
internals.That might just be my familiarity with
base64
, though. :)