nano-crypto
v1.0.0
Published
Nano ID + Crypto utility functions with full Typescript support.
Downloads
50
Maintainers
Readme
nano-crypto
Nano ID + Crypto utility functions with full Typescript support.
nano-crypto has ported nanoid/format
and nanoid/random
functions only completely to Typescript (view nanoid directory) for a seamlessly random bytes support in the scope of this package. For full and custom support please refer to the original one at github.com/ai/nanoid.
Install
yarn add nano-crypto --dev
npm install nano-crypto --save-dev
API
random
Uses Nano ID to generate secure random strings.
import { random } from 'nano-crypto'
random(40).numeric()
// 3531659724881516282463567169208265077954
random(40).hex()
// b6813a57551935ea5f69d693abd1a57a9b7b8448
random(40).alpha())
// uEUoHDftxzpbUQBBwOQKjQdRRpdIThsTMmSztsBs
random(40).alphalower()
// xjqwbtenbxdeilzaukayfzwpzisjjwgmkgjitwzm
random(40).alphaupper()
// RUHVVVOPUAYDCVICUHPPVQJWQFHYTERRGHITAHRF
random(40).alphanumeric()
// 7g9mgBSHVuXNdzyVhWijvTB6ylf6h39kuEaX8GeZ
random(40).custom('ABC')
// AABCABABBABABABAACAACBBBCCCAAABAAAABAACA
digest
Uses node crypto to generate hash digests.
import { digest } from 'nano-crypto'
digest('md5').hash('HOLA')
// c6f00988430dbc8e83a7bc7ab5256346
digest('sha1').hash('HOLA')
// 261c5ad45770cc14875c8f46eaa3eca42568104a
digest('sha256').hash('HOLA')
// 73c3de4175449987ef6047f6e0bea91c1036a8599b43113b3f990104ab294a47
digest('sha512').hash('HOLA')
// 5cf58927b41378bcc076b26b3b850a66ebcec3ace74f6b949da5405721dd39488a238f5afff793b5125038bb1dd7184c1c11c47f4844d1ccbb310c9c75893b65
cipher
Uses node crypto to encrypt data via cipher algorithms.
import { cipher } from 'nano-crypto'
const key = 'secret_key'
const { encrypt, encrypt } = cipher('aes-128-cbc', key)
const encrypted = encrypt('HOLA')
// fc584c8dd423026c824c7077a38cc387
const decrypted = decrypt(encrypted)
// HOLA
Contributions
Feel free to send some pull request or issue.
License
MIT license
© 2018-present Jose Quintana