Elliptic Curve Cryptography Helper Library
Discalaimer: This library contains encryption software that is subject to the U.S. Export Administration Regulations. You may not export, re-export, transfer or download this code or any part of it in violation of any United States law, directive or regulation. In particular this software may not be exported or re-exported in any form or on any media to Iran, North Sudan, Syria, Cuba, or North Korea, or to denied persons or entities mentioned on any US maintained blocked list.
Provides basic functions to start using ECC in your next project. Please see
Features section for a quick description of what is available.
- aescbc128: Encrypt and decrypt using AES-CBC-128 scheme.
- aescbc192: Encrypt and decrypt using AES-CBC-192 scheme.
- aescbc256: Encrypt and decrypt using AES-CBC-256 scheme.
- aesgcm128: Encrypt and decrypt using AES-GCM-128 scheme.
- aesgcm192: Encrypt and decrypt using AES-GCM-192 scheme.
- aesgcm256: Encrypt and decrypt using AES-GCM-256 scheme.
- base62: Base62 Encode/decode functions.
- base64: Base64 URL encode/decode functions.
- common: Random string, numbers, and UTC timestamp.
- ecc256: ECC with P-256 functions. Also contains functions to sign and verify the signatures, and convert PEM certificates to JWK.
- ecc384: ECC with P-384 functions. Also contains functions to sign and verify the signatures, and convert PEM certificates to JWK.
- ecc521: ECC with P-521 functions. Also contains functions to sign and verify the signatures, and convert PEM certificates to JWK.
- hash: SHA-256, SHA-384, and SHA-512 functions.
- hmac: Generate HMAC.
- hkdf: Key contraction and expansion algorithm to derive additional bytes.
- jwt: Generate and verify JSON Web Tokens. The JWTs support ES384, ES512, HS384, and HS512 algorithms.
- ksuid: Generate and parse KSUID identifiers. You can use this instead of a UUID.
- password: Password hash and match functions. Uses Scrypt + HKDF for password hashing.
- rsa: Generate key pairs, perform public key encryption and private key decryption, sign and verify using private and public keys respectively. Convert RSA keys between PEM and JWK.
- Install the library.
$> yarn add ecc-crypto-helper
- Just import the file in your NodeJS project and start using it.
// Import individual librariesvar common = ;common;
var eccHelper =// Generate a random valuevar random = await eccHelpercommon;// Generate a random number between 1 and 100var randomNumber = await eccHelpercommon;// Base64 URL encode a stringvar encoded = await eccHelperbase64;// Hash a password before storing it in your databasevar plainPassword = "I am a super password";var hashedPassword = await eccHelperpasswordhashplainPassword;// Did the user supply the correct password?var passwordMatch = await eccHelperpassword;if passwordMatch// Let the user in to the applicationelse// Password was not correct// Encrypt a string using AES-GCM-256var password = "This is a secret";var cipherText = await eccHelperaesGcm256;// Decrypt the previously encrypted stringvar plainText = await eccHelperaesGcm256;// Derive a random set of characters using HKDFvar initialKeyMaterial = "This is a secret";var size = 64;var bytesBuffer = await eccHelperhkdf;// Generate a JSON Web Token using HS512var sharedSecret = "This is a secret";var claims = "username":"bob";var webToken = await eccHelperjwths512;// Decode the JSON Web Tokenvar decodedToken = await eccHelperjwt;// Generate a RSA key pairvar rsaKeyPair = await eccHelperrsa // 1024, 2048, or 4096var jwkPrivateKey = await eccHelperrsavar jwkPublicKey = await eccHelperrsavar rsaPrivateKey = await eccHelperrsavar rsaPublicKey = await eccHelperrsa// Generate an ECDH key pairvar keyPair = await eccHelperecc521;// Generate a JSON Web Token using ES512webToken = await eccHelperjwtes512;// Create and parse KSUIDvar ksuid = await eccHelperksuid;var parsed = await eccHelperksuid;// Generate a shared secretvar sharedSecret = await eccHelpersharedSecretGenerator // 256-bit keyvar sharedSecretToJSONWebKey = await eccHelpersharedSecretGeneratorvar sharedSecretAsJSONWebKey = await eccHelpersharedSecretGenerator // 256-bit key
test/spec.js file for more examples.