Hash generates a hash using pbkdf2. See the Compare() comment for rationale.
(password string)
| 112 | // Hash generates a hash using pbkdf2. |
| 113 | // See the Compare() comment for rationale. |
| 114 | func Hash(password string) (string, error) { |
| 115 | salt := make([]byte, defaultSaltSize) |
| 116 | _, err := rand.Read(salt) |
| 117 | if err != nil { |
| 118 | return "", xerrors.Errorf("read random bytes for salt: %w", err) |
| 119 | } |
| 120 | |
| 121 | return hashWithSaltAndIter(password, salt, defaultHashIter), nil |
| 122 | } |
| 123 | |
| 124 | // Produces a string representation of the hash. |
| 125 | func hashWithSaltAndIter(password string, salt []byte, iter int) string { |