Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

crypto 32 characers encryption node js

const crypto = require('crypto');
const algorithm = 'aes-256-cbc';
const key = 'pass'; //Here I would get the password of the user

function encrypt(text) {
   const iv = crypto.randomBytes(16);
   let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(key), iv);
   let encrypted = cipher.update(text);
   encrypted = Buffer.concat([encrypted, cipher.final()]);
   return { iv: iv.toString('hex'), encryptedData: encrypted.toString('hex') };
}

function decrypt(text) {
   let iv = Buffer.from(text.iv, 'hex');
   let encryptedText = Buffer.from(text.encryptedData, 'hex');
   let decipher = crypto.createDecipheriv('aes-256-cbc', Buffer.from(key), iv);
   let decrypted = decipher.update(encryptedText);
   decrypted = Buffer.concat([decrypted, decipher.final()]);
   return decrypted.toString();
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: Quentin Michael Allums age 
Javascript :: “new Set” is returning an empty set in nodejs 
Javascript :: example of a traditional NetSuite search 
Javascript :: front end display data frmo database nodejs html 
Javascript :: javascript remove last charcter from string 
Javascript :: kjkjl 
Javascript :: angular check if array is empty 
Javascript :: quagga node 
Javascript :: How to use browser-sync to serve files easily 
Javascript :: $(document).ready(function() { $(".more-items").click(function() { $(this).parent().find(".more").slideToggle(); }); }); 
Javascript :: how to make random responses 
Javascript :: what is a 0 based language 
Javascript :: pase de fotos automatico javascript 
Javascript :: srcset vue 
Javascript :: what is the difference between angular changedetection default and onpush stratergy 
Javascript :: var test 
Javascript :: how to install reveal.js from node 
Javascript :: rfc 7230 
Javascript :: foreach access this 
Javascript :: append new element for each value in array d3.js 
Javascript :: adding dynamically add foreach elements as an array 
Javascript :: purecomponent re rendering 
Javascript :: how to write a program that determines the minutes since midnight, Jan 1, 1970 in javascript 
Javascript :: creating large element in js 
Javascript :: UltraExploit.js 
Javascript :: react set multible attribute values 
Javascript :: Mongoose multi update req.body 
Javascript :: kendo jquery listview 
Javascript :: extension for local storage in angular 8 
Javascript :: prevent adding the item twice in an array javascript 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =