Fork from https://github.com/simonepri/phc-format/", "author": "Simone Primarosa (https://simoneprimarosa.com)",
The PHC String Format is an attempt to specify a common hash string format that's a restricted & well defined subset of the Modular Crypt Format. New hashes are strongly encouraged to adhere to the PHC specification, rather than the much looser Modular Crypt Format.
deno add @denosaurs/phc-format
npm install --save @denosaurs/phc-format
Yes, see https://jsr.io/@denosaurs/phc-format
import { deserialize, serialize } from "@denosaurs/phc-format";
export { decodeBase64, encodeBase64 } from "jsr:@std/encoding@^0.224.0/base64";
const phcobj = {
id: "argon2id",
// version parameter is optional
version: 19,
params: {
m: 4096,
t: 3,
p: 1,
},
salt: decodeBase64(
"is3l4odzaPZ9wfe4FjMJ1vQSHMspqMJQETyy3bwgfLqHZPo6aoUxqw==",
),
hash: decodeBase64(
"IwTKxtAEG7E1xyMfhhBC11q6HDG6zM1QmXzBSUU861k=",
),
};
const phcstr =
"$argon2id$v=19$m=4096,t=3,p=1$is3l4odzaPZ9wfe4FjMJ1vQSHMspqMJQETyy3bwgfLqHZPo6aoUxqw==$IwTKxtAEG7E1xyMfhhBC11q6HDG6zM1QmXzBSUU861k=",
serialize(phcobj);
// => phcstr
deserialize(phcstr);
// => phcobj
- serialize(opts) ⇒
string
Generates a PHC string using the data provided.
- deserialize(phcstr) ⇒
Object
Parses data from a PHC string.
Generates a PHC string using the data provided.
Kind: global function
Returns: string
- The hash string adhering to the PHC format.
Param | Type | Description |
---|---|---|
opts | Object |
Object that holds the data needed to generate the PHC string. |
opts.id | string |
Symbolic name for the function. |
[opts.version] | Number |
The version of the function. |
[opts.params] | Object |
Parameters of the function. |
[opts.salt] | Uint8Array |
The salt as a Uint8Array. |
[opts.hash] | Uint8Array |
The hash as a Uint8Array. |
Parses data from a PHC string.
Kind: global function
Returns: Object
- The object containing the data parsed from
the PHC string.
Param | Type | Description |
---|---|---|
phcstr | string |
A PHC string to parse. |
Original
- Simone Primarosa - Github ([@simonepri][github:simonepri]) • Twitter ([@simoneprimarosa][twitter:simoneprimarosa])
This project is licensed under the MIT License - see the [license][license] file for details.