Giter VIP home page Giter VIP logo

phc-format's Introduction

phc-format

Fork from https://github.com/simonepri/phc-format/", "author": "Simone Primarosa (https://simoneprimarosa.com)",

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

Deno

deno add @denosaurs/phc-format

Node

npm install --save @denosaurs/phc-format

Bun and others languages

Yes, see https://jsr.io/@denosaurs/phc-format

Usage

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

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] Uint8Array The salt as a Uint8Array.
[opts.hash] Uint8Array The hash as a Uint8Array.

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

Authors

Original

  • Simone Primarosa - Github ([@simonepri][github:simonepri]) • Twitter ([@simoneprimarosa][twitter:simoneprimarosa])

License

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

phc-format's People

Contributors

hapaxlife avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.