npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@phc/format

v1.0.0

Published

PHC string format serializer/deserializer

Downloads

1,304,195

Readme

Motivation

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.

Install

npm install --save @phc/format

Usage

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);
// => phcstr

phc.deserialize(phcstr);
// => phcobj

You can also pass an optional version parameter.

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);
// => phcstr

phc.deserialize(phcstr);
// => phcobj

API

TOC

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.
Please check the contributing guidelines for more details. Thanks!

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the license file for details.