Node Crypto JS
Introduction
Node Crypto JS is a NodeJS (RSA+AES) encryption and decryption companion for hybrid-crypto-js. Node Crypto JS combines RSA and AES encryption algorithms making it possible to efficiently encrypt and decrypt large messages. This node library is based on hybrid-crypto-js.
Documentation
Getting started
Features
Installation
npm install node-crypto-js
Importing
Node.js
var RSA = RSA;var Crypt = Crypt;
Features
Initialization
// Basic initializationvar crypt = ;var rsa = ; // Increase amount of entropyvar entropy = 'Random string, integer or float';var crypt = entropy: entropy ;var rsa = entropy: entropy ;
Encryption
Node Crypto JS provides basic encryption function which supports also multiple RSA keys, with or without signature. Encrypted message is outputted as a JSON string.
var message = 'Hello world!'; // Encryption with one public RSA keyvar encrypted = crypt; // Function also supports encryption with multiple RSA public keysvar encrypted = crypt; // Encryption with signaturevar encrypted = crypt;
Pretty-printed sample output
"v": "node-crypto-js_0.1.2" // Current package version "iv": "CmtyaZTyzoAp1mTNUTztic0v1..." // Initialization vector "keys": // Encrypted AES keys by RSA fingerprints "85:3d:10:e1:56...": "bHaTF9..." "d3:48:6a:e9:13...": "t9eds3..." "cipher": "+iwVFsC2dECBQvwcm9DND..." // Actual encrypted message "signature": "sdL93kfdm12feds3C2..." // Signature (optional)
Decryption
Decrypting message with Hybrid Crypto JS is as easy as encrypting. Decryption function can decrypt any message which has been encrypted with keypair's public key. Decrypted message is outputted as a JSON object.
var encrypted = '{"v":"node-crypto-js_0.1.0","iv":"CmtyaZTyzoAp1mTN...'; // Decrypt encryped message with private RSA keyvar decrypted = crypt; // Get decrypted messagevar message = decryptedmessage;
Sample output
message: "Hello world!" // Actual decrypted message signature: "sdL93kfdm12feds3C2..." // Signature (optional)
Signatures
Hybrid Crypto JS provides simple message signing. When issuer signs a message, message receiver can be sure of the message issuer.
var message = 'Hello world!'; // Create a signature with ISSUER's private RSA keyvar signature = crypt; // Encrypt message with RECEIVERS public RSA key and attach the signaturevar encrypted = crypt;
Verifying
Message receiver needs to have message issuer's public RSA key in order to verify message issuer.
// Encrypted message with signaturevar encrypted = '{"v":"hybri... ..."signature":"sdL93kfd...'; // Decrypt message with own (RECEIVER) private keyvar decrypted = crypt; // Verify message with ISSUER's public keyvar verified = crypt;
Verification function return true or false depending on whether the verification was successfull.
RSA keypairs
Hybrid Crypto JS RSA key generation function is based in Forge key pair generation function. As a difference Hybrid Crypto JS returns keypair in PEM format.
// Initialize RSA-classvar rsa = ; // Generate RSA key pair, defaults on 4096 bit keyrsa; // Generate 1024 bit RSA key pairrsa; // Key size // RSA can be also initialized with optionsvar rsa = keySize: 4096 rsaStandard: 'RSA-OAEP' // RSA-OAEP or RSAES-PKCS1-V1_5,;