Portal:
# crypto- js GitHubhttps: // Github.com/brix/crypto-js
Demo1:
//Load Core Cryptographic librariesvarCryptojs = require ("Crypto-js");//Loading des algorithmvarTripleDES = require ("Crypto-js/tripledes");//start encryption, and return ciphertextvarciphertext = Tripledes.encrypt ("fuckyou",'123'). toString ();//decryptionvarplaintext = Tripledes.decrypt (ciphertext,'123'). toString (CryptoJS.enc.Utf8)//output ciphertext and decrypted contentConsole.log (ciphertext, plaintext)
Demo2:
//Load Core Cryptographic librariesvarCryptojs = require ("Crypto-js"); function encrypt (message, key) {varKeyhex =CryptoJS.enc.Utf8.parse (key); varencrypted =CryptoJS.DES.encrypt (Message, Keyhex, {Mode:CryptoJS.mode.ECB, padding:CryptoJS.pad.Pkcs7}); return{key:keyhex, value:encrypted.toString ()}}function decrypt (message, key) {varplaintext =CryptoJS.DES.decrypt (message, key, {Mode:CryptoJS.mode.ECB, padding:CryptoJS.pad.Pkcs7}) returnplaintext.tostring (CryptoJS.enc.Utf8)}varA = Encrypt ('mssage123','123');varb =Decrypt (A.value, A.key); Console.log (a.value.length)
The front end uses CRYPTO-JS to encrypt data symmetrically