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

@sapphirecode/crypto-helper

v2.1.2

Published

simple functions for cryptography

Downloads

37

Readme

@sapphirecode/crypto-helper

version: 2.1.x

simple functions for cryptography

Installation

npm:

npm i --save @sapphirecode/crypto-helper

yarn:

yarn add @sapphirecode/crypto-helper

Usage

Examples

const crypto = require('@sapphirecode/crypto-helper');

const rand_hex = crypto.random_hex(16); // outputs 16 byte random hex
const rand_salt = crypto.create_salt(); // same as random_hex, but with fixed length of 32 bytes
const random_string = crypto.random_string(16); // output 16 character long random string
const hash = crypto.hash_sha512(random_string, random_hex); // returns sha 512 hex
const check = crypto.checksum('foo'); // returns a sha 256 hex
const scrypt_hash = await crypto.pbkdf_scrypt('foo', 'bar'); // returns a scrypt hash

// jwt like object signing
const signed = crypto.sign_object({foo: 'bar'}, 'secret');
const info = await crypto.get_signature_info(signed); // returns an object with iat (issued at), key_info and data
const dec = await crypto.decode_signed(signed); // decode a signed object without verifying the signature
const ver = await crypto.verify_signature(signed, 'secret', 10000); // verifies the signature and returns the contents. the timeout is in milliseconds and optional, timing will be ignored if omitted.
const ver_info = await crypto.verify_signature_get_info(signed, 'secret', 10000); // verify a signature and get signature information like iat and key_info
const ver_func = await crypto.verify_signature(
  signed,
  (signature_info) => 'secret',
  10000
); // verify a signature, retrieve the key using the signature info

// encryption
const enc = crypto.encrypt_aes('foo', 'bar');
const dec = crypto.decrypt_aes(enc, 'bar');

// asymmetric encryption and signatures
const keys = await crypto.generate_keypair(2048); // generate private and public key (length is optional and 2048 by default)

const aenc = crypto.asym_encrypt('foo', keys.public_key); // encrypt
const adec = crypto.asym_decrypt(aenc, key.private_key); // decrypt

const asig = crypto.asym_sign('foo', keys.private_key); // create signature
const aver = crypto.asym_verify('foo', keys.public_key, asig); // verify signature, returns boolean

Asymmetric signatures on object signing

the functions sign_object, verify_signature, ... will automatically detect rsa keys and use them to sign objects asymmetrically. Note that keys have to be provided in the correct order (private key for signing, public key for verifying). Else the keys will just be interpreted as symmetric and verification will fail.

License

MIT © Timo Hocker [email protected]