Nodejs is a crypto module integrated into the kernel to complete encryption and decryption.
Common encryption and decryption of modular code:
/** * Created by Linli on 2015/8/25.*/varCrypto = require (' crypto '));//EncryptExports.cipher =function(algorithm, key, buf) {varencrypted = ""; varCIP =crypto.createcipher (algorithm, key); Encrypted+ = Cip.update (buf, ' binary ', ' hex ')); Encrypted+ = cip.final (' hex ')); returnencrypted};//decryptionExports.decipher =function(algorithm, key, encrypted) {vardecrypted = ""; varDecipher =crypto.createdecipher (algorithm, key); Decrypted+ = Decipher.update (encrypted, ' hex ', ' binary ')); Decrypted+ = decipher.final (' binary '); returndecrypted};
Here, only reversible encryption is targeted.
For more detailed information, please visit: http://blog.fens.me/nodejs-crypto/
Nodejs Encryption and decryption