Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/simonepri/phc-format
📝 PHC String Format implementation for Node.JS
https://github.com/simonepri/phc-format
competition crypt crypto decode deserialize deserializer encode format hashing mcf nodejs parser password phc serialize serializer standard string
Last synced: 2 months ago
JSON representation
📝 PHC String Format implementation for Node.JS
- Host: GitHub
- URL: https://github.com/simonepri/phc-format
- Owner: simonepri
- License: mit
- Created: 2018-03-08T00:07:40.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-07-20T04:14:49.000Z (over 3 years ago)
- Last Synced: 2024-10-20T10:58:32.362Z (2 months ago)
- Topics: competition, crypt, crypto, decode, deserialize, deserializer, encode, format, hashing, mcf, nodejs, parser, password, phc, serialize, serializer, standard, string
- Language: JavaScript
- Size: 39.1 KB
- Stars: 17
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
phc-format
📝 PHC string format serializer/deserializer
Coded with ❤️ by Simone Primarosa.
## Motivation
The [PHC String Format][specs:phc] 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][specs:mcf].## Install
```bash
npm install --save @phc/format
```## Usage
```js
const phc = require('@phc/format');const phcobj = {
id: 'pbkdf2-sha256',
params: {i: 6400},
salt: Buffer.from('0ZrzXitFSGltTQnBWOsdAw', 'base64'),
hash: Buffer.from('Y11AchqV4b0sUisdZd0Xr97KWoymNE0LNNrnEgY4H9M', 'base64'),
};const phcstr = "$pbkdf2-sha256$i=6400$0ZrzXitFSGltTQnBWOsdAw$Y11AchqV4b0sUisdZd0Xr97KWoymNE0LNNrnEgY4H9M";
phc.serialize(phcobj);
// => phcstrphc.deserialize(phcstr);
// => phcobj
```You can also pass an optional version parameter.
```js
const phc = require('@phc/format');const phcobj = {
id: 'argon2i',
version: 19,
params: {
m: 120,
t: 5000,
p: 2
},
salt: Buffer.from('iHSDPHzUhPzK7rCcJgOFfg', 'base64'),
hash: Buffer.from('J4moa2MM0/6uf3HbY2Tf5Fux8JIBTwIhmhxGRbsY14qhTltQt+Vw3b7tcJNEbk8ium8AQfZeD4tabCnNqfkD1g', 'base64'),
};const phcstr = "$argon2i$v=19$m=120,t=5000,p=2$iHSDPHzUhPzK7rCcJgOFfg$J4moa2MM0/6uf3HbY2Tf5Fux8JIBTwIhmhxGRbsY14qhTltQt+Vw3b7tcJNEbk8ium8AQfZeD4tabCnNqfkD1g";
phc.serialize(phcobj);
// => phcstrphc.deserialize(phcstr);
// => phcobj
```## API
#### TOC
-
serialize(opts) ⇒string
-
Generates a PHC string using the data provided.
-
deserialize(phcstr) ⇒Object
-
Parses data from a PHC string.
### serialize(opts) ⇒ 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] | Buffer
| The salt as a binary buffer. |
| [opts.hash] | Buffer
| The hash as a binary buffer. |
### deserialize(phcstr) ⇒ Object
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. |
## Contributing
Contributions are REALLY welcome and if you find a security flaw in this code, PLEASE [report it][new issue].
Please check the [contributing guidelines][contributing] for more details. Thanks!
## Authors
- **Simone Primarosa** - *Github* ([@simonepri][github:simonepri]) • *Twitter* ([@simoneprimarosa][twitter:simoneprimarosa])
See also the list of [contributors][contributors] who participated in this project.
## License
This project is licensed under the MIT License - see the [license][license] file for details.
[start]: https://github.com/simonepri/phc-format#start-of-content
[new issue]: https://github.com/simonepri/phc-format/issues/new
[contributors]: https://github.com/simonepri/phc-format/contributors
[license]: https://github.com/simonepri/phc-format/tree/master/license
[contributing]: https://github.com/simonepri/phc-format/tree/master/.github/contributing.md
[github:simonepri]: https://github.com/simonepri
[twitter:simoneprimarosa]: http://twitter.com/intent/user?screen_name=simoneprimarosa
[specs:mcf]: https://github.com/ademarre/binary-mcf
[specs:phc]: https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md