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

crypto-extra

v1.0.1

Published

Convenience methods for the crypto module

Downloads

62,281

Readme

Crypto-Extra for Node.js

Build Status Coverage Status

Adds convenience methods to the native Node.js crypto module. It is a drop in replacement, and extends the original module functionality.

Why?

The native crypto module can be a pain to work with, and requires a lot of boilerplate to do things such as randomizing and encryption. This abstracts all of that.

Getting Started

$ npm install crypto-extra --save

To use in your project, simply require into your project as you would the crypto module.

const crypto = require("crypto-extra")

crypto.randomString()
//= L0e84MUt0n

crypto.hash("hello")
//= 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

API

.encrypt (value, secretKey)

Encrypts a value with a secret key using AES-256-CTR.

  • value - The value you want to encrypt. Everything (except objects) is converted to a string before encryption for consistency. Objects are stringified using JSON.stringify.

    Type: any

  • secretKey - The key used in the encryption. If not supplied, the lib will fallback to the environment variable ENCRYPTION_KEY.

    Type: string
    Default: process.env.ENCRYPTION_KEY

.decrypt (value, secretKey)

Decrypts a value using AES-256-CTR.

  • value - The encrypted value you want to decrypt. Will automatically parse objects that were encrypted.

    Type: string

  • secretKey - The key used in the encryption. If not supplied, the lib will fallback to the environment variable ENCRYPTION_KEY.

    Type: string
    Default: process.env.ENCRYPTION_KEY

.hash (value, options)

Hashes a string with the provided algorithm.

  • value - The value you want to hash. Any non-string value is converted to a string before hashing for consistency.

    Type: string

  • options

    • rounds - The number of rounds to use when hashing.

      Type: integer
      Default: 1

    • salt - A string to be appended to the value before it is hashed.

      Type: string

    • algorithm - The hashing algorithm to use.

      Type: string
      Default: SHA256

.randomKey (length)

Generates a random 256-bit key that can be used as an encryption key.

  • length - The length of the key you want to generate. Must be an even number.

    Type: number
    Default: 32

.randomString (length, charset)

Returns a random string of a defined length.

  • length - Length of the random string. Must be above 0.

    Type: integer
    Default: 10

  • charset - The character set to take from.

    Type: string
    Default: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789

.randomNumber (options)

Returns a random string within a defined range.

  • options

    • min - Minimum number of range. Must be a positive integer.

      Type: integer
      Default: 0

    • max - Maximum number of range. This cannot be higher than 9007199254740991 due to Javascript integer limits (http://mzl.la/1A1nVyU). If you need a number higher than this, consider using randomString with the charset 0123456789 instead.

      Type: integer
      Default: 9007199254740991

License

MIT © Jason Maurer