Skip to content

Crypto

Created: 2016-09-06 13:17:36 -0700 Modified: 2016-09-06 13:18:29 -0700

  • Most of this page is about the Crypto library.
  • Note that you don’t need to require Buffer in Node.

(this is useful when you want to encrypt something and later be able to decrypt it with a single key)

const crypto = require(‘crypto’);

const password = ‘a password’;

const cipher = crypto.createCipher(‘aes192’, password);

var encrypted = cipher.update(‘some clear text data’, ‘utf8’, ‘hex’);

encrypted += cipher.final(‘hex’);

console.log(encrypted);

// Prints: ca981be48e90867604588e75d04feabb63cc007a8f8ad89b10616ed84d815504

const decipher = crypto.createDecipher(‘aes192’, password);

var decrypted = decipher.update(encrypted, ‘hex’, ‘utf8’);

decrypted += decipher.final(‘utf8’);

console.log(decrypted);

// Prints: some clear text data