Created
March 31, 2017 12:16
-
-
Save AukeTembrink/955d534340ba8c7606234e2383ea82aa to your computer and use it in GitHub Desktop.
Textverschlüsselung mit crypto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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