data at transit encrypting nodejs stack overflow

Solutions on MaxInterview for data at transit encrypting nodejs stack overflow by the best coders in the world

showing results for - "data at transit encrypting nodejs stack overflow"
Giacomo
23 Feb 2019
1var crypto = require('crypto');
2var assert = require('assert');
3
4var algorithm = 'aes256'; // or any other algorithm supported by OpenSSL
5var key = 'password';
6var text = 'I love kittens';
7
8var cipher = crypto.createCipher(algorithm, key);  
9var encrypted = cipher.update(text, 'utf8', 'hex') + cipher.final('hex');
10var decipher = crypto.createDecipher(algorithm, key);
11var decrypted = decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8');
12
13assert.equal(decrypted, text);