Skip to content

Instantly share code, notes, and snippets.

@AukeTembrink
Created March 31, 2017 12:16
Show Gist options
  • Save AukeTembrink/955d534340ba8c7606234e2383ea82aa to your computer and use it in GitHub Desktop.
Save AukeTembrink/955d534340ba8c7606234e2383ea82aa to your computer and use it in GitHub Desktop.
Textverschlüsselung mit crypto
var crypto = require('crypto'),
algorithm = 'aes-256-ctr',
password = 'ThisIsAUserPassword';
function encrypt(text){
var cipher = crypto.createCipher(algorithm, password)
var crypted = cipher.update(text, 'utf8', 'hex')
crypted += cipher.final('hex');
return crypted;
}
function decrypt(text){
var decipher = crypto.createDecipher(algorithm,password)
var decrypted = decipher.update(text,'hex','utf8')
decrypted += decipher.final('utf8');
return decrypted;
}
var hw = encrypt("Hello World");
console.log('Verschlüsselt: \n' + hw + '\n');
console.log('Entschlüsselt: \n' + decrypt(hw));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment