Skip to content

Instantly share code, notes, and snippets.

@humphd
Last active July 31, 2020 16:38
Show Gist options
  • Save humphd/af06d7033db38590632661d299a2eaf6 to your computer and use it in GitHub Desktop.
Save humphd/af06d7033db38590632661d299a2eaf6 to your computer and use it in GitHub Desktop.
Encoding, Hashing, Salting, Encryption
/**
* Encoding
*/
const text = 'This is a sentence.';
const buf = Buffer.from(text);
console.log({
text,
base64: buf.toString('base64'),
hex: buf.toString('hex'),
url: encodeURIComponent(text)
});
/**
* Hashing
*/
const crypto = require('crypto');
const data = 'This is our input data. It can be really, really long and that is OK!';
console.log({
data,
sha1: crypto.createHash('sha1').update(data).digest('base64'),
sha256: crypto.createHash('sha256').update(data).digest('base64'),
md5: crypto.createHash('md5').update(data).digest('base64')
});
/**
* Salting + Hashing with bcrypt
*/
const bcrypt = require('bcrypt');
const password = 'Sup3rS3creT!';
console.log({
password,
encrypted: bcrypt.hashSync(password, 14)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment