Node.JS Copy-Paste-Run-Ready string encryption / decryption with AES-256 in Node.JS /* --- Code ready to copy -> paste -> run --- */ // Libraries const crypto = require('crypto'); const ENCODING = "hex"; // hex or base64 // Implementations function encryptAES256(clearMsg, key) { let iv = crypto.randomBytes(16); // Generating 16 byte random IV let cipher = crypto.createCipheriv( "aes256", crypto.createHash("sha256").update(key, "utf8").digest(), // 32 bytes
Node.JS Shortest and simplest string encryption / decryption with AES-256 in Node.JS Copy and paste the following code in a .js file, then run it. // Libraries const crypto = require('crypto'); // Constants const OUTPUT_FORMAT = "hex"; const ALGORITHM = "aes256"; const KEY = "012345ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const IV = "ABCDEF0123456789"; // Implementations function encrypt(message) { let cipher = crypto.createCipheriv( ALGORITHM, Buffer.from(KEY), Buffer.from(IV) ); return (Buffer.concat(
Node.JS Encrypt / Decrypt with AES (CCM & GCM) in Node.JS (Part 2 – Concatenate the Authentication Tag) In the past I wrote a post about encrypting and decrypting text strings with AES in GCM and CCM mode. At the time, the demo was written to show how the algorithm works in those modes. Today I needed to handle the inclusion of such Authentication Tag inside the encrypted
Node.JS Elliptic Curve Diffie-Hellman and AES Example in Node.JS Recently I learned how to generate shared secrets using ECDH in Node.JS, but I still had to know how to use this shared secret. Here is one application for it. Use the ECDH to generate a shared secret and then use that shared secret to cipher/decipher messages between
Node.JS How to Encrypt / Decrypt with AES in Node.JS Easy as pie! var crypto = require('crypto'); var AES128 = "aes128"; var AES192 = "aes192"; var AES256 = "aes256"; var password = 'Austin'; var plainText = 'Texas to the bone!'; // ------------------------------------------------ var cipher = crypto.createCipher(AES128, password); var decipher = crypto.createDecipher(AES128, password); console.log('AES-128:'); // Encrypting with AES128 var encText = cipher.update(
Java How to Encrypt / Decrypt with AES in Java 1.8 Here I have created a class that does it in two different ways, the first one is, when you create the key, and the other is when you are given the key, valid key sizes are 128, 192, and 256 for AES algorithm. There is some steps to follow before