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

@xutils/crypto

v1.1.15

Published

used for encryption methods above ES6, supporting Nodejs and browsers

Downloads

81

Readme

@xutils/crypto

Encryption toolkit based on ES6 and above, supporting md5, ripemd160, sha1, sha2, sha3, hmac, aes, des, tripledes, pbkdf2, rabbit, rc4, and rsa.

Installation

npm install @xutils/crypto

Usage

use in md5

import { md5, Md5, createHash } from '@xutils/crypto';

console.log(md5('hello world'));// 5eb63bbbe01eeed093cb22bb8f5acdc3
console.log(md5('hello world', { length: 16 }));// e01eeed093cb22bb
console.log(md5('hello world', { upper: true }));// 5EB63BBBE01EEED093CB22BB8F5ACDC3
console.log(md5('hello world', { upper: true, length: 16 }));// E01EEED093CB22BB

console.log(new Md5().update('hello world').digest());// 5eb63bbbe01eeed093cb22bb8f5acdc3
console.log(new Md5().update('hello world').digest({ length: 16 }));// e01eeed093cb22bb
console.log(new Md5().update('hello world').digest({ upper: true }));// 5EB63BBBE01EEED093CB22BB8F5ACDC3
console.log(new Md5().update('hello world').digest({ upper: true, length: 16 }));// E01EEED093CB22BB

console.log(createHash('md5').update('hello world').digest());// 5eb63bbbe01eeed093cb22bb8f5acdc3
console.log(createHash('md5').update('hello world').digest({ length: 16 }));// e01eeed093cb22bb
console.log(createHash('md5').update('hello world').digest({ upper: true }));// 5EB63BBBE01EEED093CB22BB8F5ACDC3
console.log(createHash('md5').update('hello world').digest({ upper: true, length: 16 }));// E01EEED093CB22BB

use in ripemd160

import { ripeMd160, RipeMd160, createHash } from '@xutils/crypto';

console.log(ripeMd160('hello world'));// 98c615784ccb5fe5936fbc0cbe9dfdb408d92f0f
console.log(ripeMd160('hello world', { upper: true }));// 98C615784CCB5FE5936FBC0CBE9DFDB408D92F0F
console.log(ripeMd160('hello world', { type: 'base64' }));// mMYVeEzLX+WTb7wMvp39tAjZLw8=

console.log(new RipeMd160().update('hello world').digest());// 98c615784ccb5fe5936fbc0cbe9dfdb408d92f0f
console.log(new RipeMd160().update('hello world').digest({ upper: true }));// 98C615784CCB5FE5936FBC0CBE9DFDB408D92F0F
console.log(new RipeMd160().update('hello world').digest({ type: 'base64' }));// mMYVeEzLX+WTb7wMvp39tAjZLw8=

console.log(createHash('ripemd160').update('hello world').digest());// 98c615784ccb5fe5936fbc0cbe9dfdb408d92f0f
console.log(createHash('ripemd160').update('hello world').digest({ upper: true }));// 98C615784CCB5FE5936FBC0CBE9DFDB408D92F0F
console.log(createHash('ripemd160').update('hello world').digest({ type: 'base64' }));// mMYVeEzLX+WTb7wMvp39tAjZLw8=   

Refer to ripemd160 for the use of sha1,sha224,sha256,sha384,sha512,sha3-224,sha3-256,sha3-384 and sha3-512.

use in hmacmd5

import { hmacMd5, HmacMd5, createHmac } from '@xutils/crypto';

console.log(hmacMd5('hello world', 'my key')); // 08603c966d17f021cf5d2dcb277f6e04
console.log(new HmacMd5('my key').update('hello world').digest()); // 08603c966d17f021cf5d2dcb277f6e04
console.log(createHmac('md5', 'my key').update('hello world').digest()); // 08603c966d17f021cf5d2dcb277f6e04

Refer to hmacmd5 for the use of hmacripemd160,hmacsha1,hmacsha224,hmacsha256,hmacsha384,hmacsha512,hmacsha3-224,hmacsha3-256,hmacsha3-384 and hmacsha3-512.

use in pbkdf2

import { pbkdf2, Pbkdf2, createHash } from '@xutils/crypto';

console.log(pbkdf2('hello world', { salt: 'my salt', digest: 'sha1' }));// 0d63b940893356a6abac4ecae80e753f
console.log(new Pbkdf2({ salt: 'my salt', digest: 'sha1' }).update('hello world').digest());// 0d63b940893356a6abac4ecae80e753f
console.log(createHash('pbkdf2', { salt: 'my salt', digest: 'sha1' }).update('hello world').digest());// 0d63b940893356a6abac4ecae80e753f

use in rabbit

import { rabbitEncrypt, rabbitDecrypt, Rabbit, createCipheriv, createDecipheriv } from '@xutils/crypto';

// use class Rabbit
const rabbit = new Rabbit('key', '12345678');
console.log(rabbit.decrypt(rabbit.encrypt('hello world')) === 'hello world'); // true

// use cipher function
console.log(createDecipheriv('rabbit', 'key', '12345678').decrypt(createCipheriv('rabbit', 'key', '12345678').encrypt('hello world')) === 'hello world'); // true

// use encrypt function
console.log(rabbitDecrypt(rabbitEncrypt('hello world', { key: 'key', iv: '12345678' }), { key: 'key', iv: '12345678' }) === 'hello world'); // true

Refer to rabbit for the use of rc4,des,tripledes and aes.Only when the type is inconsistent.

use in rsa

import { RSA, rsaEncrypt, rsaDecrypt } from '@xutils/crypto';

const rsa = new RSA();

// Generate key pairs
const keys = RSA.getKeys();
rsa.setKeys(keys);

console.log(rsa.decrypt(rsaEncrypt(keys.publicKey, 'hello world')) === 'hello world'); // true
console.log(rsaDecrypt(keys.privateKey, rsa.encrypt('hello world')) === 'hello world'); // true

use in nodejs

import { ... } from '@xutils/crypto/node';
...