JavaScript AES encryption and decryption (Advanced Encryption Standard)

后端 未结 6 634
礼貌的吻别
礼貌的吻别 2020-12-05 22:08

How to implement encryption and decryption using AES (Advanced Encryption Standard) in JavaScript.

Why AES (Advanced Encryption Standard) ?

Security:

6条回答
  •  不知归路
    2020-12-05 22:45

    function encrypt(message = '', key = ''){
        var message = CryptoJS.AES.encrypt(message, key);
        return message.toString();
    }
    function decrypt(message = '', key = ''){
        var code = CryptoJS.AES.decrypt(message, key);
        var decryptedMessage = code.toString(CryptoJS.enc.Utf8);
    
        return decryptedMessage;
    }
    console.log(encrypt('Hello World'));
    console.log(decrypt('U2FsdGVkX1/0oPpnJ5S5XTELUonupdtYCdO91v+/SMs='))

提交回复
热议问题