const crypto = require("crypto"); const algorithm = "aes-256-cbc"; // generate 16 bytes of random data const initVector = Buffer.from("x14v8IjF4C3m9L8Uk+sVVA==", 'base64'); // crypto.randomBytes(16); console.log(initVector.length) // protected data const message = "This is a secret message"; // secret key generate 32 bytes of random data const Securitykey = Buffer.from("d7f5x2hlB6PcwQj2odTbR7gABHkclyP41MOyZVislh4=", 'base64'); console.log(Securitykey.length) // crypto.randomBytes(32); // the cipher function const cipher = crypto.createCipheriv(algorithm, Securitykey, initVector); // encrypt the message // input encoding // output encoding let encryptedData = cipher.update(message, "utf-8", "base64"); encryptedData += cipher.final("base64"); console.log("Encrypted message: " + encryptedData); const encryptedMsg = "z32QHu7OVePKWF+2qe8lWGajs4euVTP98QdOooGQ2xpWMpzF8fcYkFhQJl9UN4ZmunePX9Tnj/SDYOFc/Pf/iKfkdNoLjamhjCY9lp4q9v47zC+MDjycPTlgLRahmjh9kj9PGRYzH/mc4aSHL+xU9AZoR6yd406M4QxRwZxWUJO8Wwyq9euoU7pTTlW1MtrTNWBxSFDvDtgJ+GPubyFvAA==" // the decipher function const decipher = crypto.createDecipheriv(algorithm, Securitykey, initVector); let decryptedData = decipher.update(encryptedMsg, "base64", "utf-8"); decryptedData += decipher.final("utf8"); console.log("Decrypted message: " + decryptedData);
Write, Run & Share NodeJS code online using OneCompiler's NodeJS online compiler for free. It's one of the robust, feature-rich online compilers for NodeJS language,running on the latest LTS version NodeJS 16.14.2. Getting started with the OneCompiler's NodeJS editor is easy and fast. The editor shows sample boilerplate code when you choose language as NodeJS and start coding. You can provide the dependencies in package.json
.
Node.js is a free and open-source server environment. Node.js is very popular in recent times and a large number of companies like Microsoft, Paypal, Uber, Yahoo, General Electric and many others are using Node.js.
Google chrome's javascript engine V8
and is pretty fast.Asynchronous
, event-driven
and works on single-thread model
thus eliminating the dis-advantages of multi-thread model.Express is one of the most popular web application framework in the NodeJS echosystem.
let moment = require('moment');
console.log(moment().format('MMMM Do YYYY, h:mm:ss a'));
const _ = require("lodash");
let colors = ['blue', 'green', 'yellow', 'red'];
let firstElement = _.first(colors);
let lastElement = _.last(colors);
console.log(`First element: ${firstElement}`);
console.log(`Last element: ${lastElement}`);
Following are the libraries supported by OneCompiler's NodeJS compiler.