Skip to content

Instantly share code, notes, and snippets.

@pujansrt
Last active July 8, 2022 15:04
Show Gist options
  • Save pujansrt/f8615a67e74118b19500a5efc586b99b to your computer and use it in GitHub Desktop.
Save pujansrt/f8615a67e74118b19500a5efc586b99b to your computer and use it in GitHub Desktop.
Two way hashing (JS)
const crypto = require('crypto');
const algorithm = 'aes256';
const salt = '900150983cd24fb0d6963f7d28e17f72';
const cryptoEncoding = 'base64';
const cipher = crypto.createCipher(algorithm, salt);
const encryptedText = cipher.update(text, 'utf8', cryptoEncoding) + cipher.final(cryptoEncoding);
const decipher = crypto.createDecipher(algorithm, salt);
const decryptedText = decipher.update(encryptedText, cryptoEncoding, 'utf8') + decipher.final('utf8');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment