Symmetric Encryption means that you can encrypt a piece of text and decrypt the encrypted text using the same key. In NodeJs “Crypto” Module helps in various cryptographic  functionality that includes a set of wrappers for OpenSSL’s hash, HMAC, cipher, decipher, sign and verify functions.

It is Easy and simple to use symmetric encryption and is very helpful in cases when you want to store information in database in encrypted form.

So here is the crypto.js file.


var crypto = require("crypto");
var key = "TheKey%%123asdasda";
var text = "Crypto Module is awesome!!";
var enc = crypto.createCipher("aes-256-ctr",key).update(text,"utf-8","hex");
var dec = crypto.createDecipher("aes-256-ctr",key).update(enc,"hex","utf-8");
console.log(enc);
console.log(dec);

As simple as that. Here “aes-256-ctr” is the type of encryption that i am using. 256 is the block size and “ctr” is the mode of encryption. You can use

crypto.getCiphers()

to print a list of all the ciphers that are available.

So here i have provided a video tutorial. Must See and subscribe my channel for more videos.

Advertisements