@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);
const rand_salt = crypto.create_salt();
const random_string = crypto.random_string(16);
const hash = crypto.hash_sha512(random_string, random_hex);
const check = crypto.checksum('foo');
const scrypt_hash = await crypto.pbkdf_scrypt('foo', 'bar');
const signed = crypto.sign_object({foo: 'bar'}, 'secret');
const info = await crypto.get_signature_info(signed);
const dec = await crypto.decode_signed(signed);
const ver = await crypto.verify_signature(signed, 'secret', 10000);
const ver_info = await crypto.verify_signature_get_info(signed, 'secret', 10000);
const ver_func = await crypto.verify_signature(
signed,
(signature_info) => 'secret',
10000
);
const enc = crypto.encrypt_aes('foo', 'bar');
const dec = crypto.decrypt_aes(enc, 'bar');
const keys = await crypto.generate_keypair(2048);
const aenc = crypto.asym_encrypt('foo', keys.public_key);
const adec = crypto.asym_decrypt(aenc, key.private_key);
const asig = crypto.asym_sign('foo', keys.private_key);
const aver = crypto.asym_verify('foo', keys.public_key, asig);
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 timo@scode.ovh