Node.js - AES Encryption and Decryption Example
Advanced Encryption Standard is a symmetric encryption algorithm. AES encryption is used by the U.S. for securing sensitive but unclassified material, so we can say it is enough secure. I t allows 128 bit, 192 bit and 256-bit encryption. Symmetric encryption is very fast as compared to asymmetric encryption and are used in systems such as database system. The following illustration highlights how symmetric cryptography works: Example 1: AES 256 Encryption and Decryption //AES 256 Encryption Demo Program // crypto module const crypto = require( "crypto" ); // encrypt the message function encrypt(plainText, securitykey, outputEncoding, iv) { const cipher = crypto. createCipheriv( "aes-256-cbc" , securitykey, iv); return Buffer. concat([cipher.update(plainText), cipher.final()]). toString(outputEncoding); } //AES decryption function decrypt(cipherText, securitykey, outputEncoding, iv) { const cipher = crypto. createDeci