Created
November 14, 2021 03:58
-
-
Save sachadee/e02c28b72c98acc810c312368b6b878b to your computer and use it in GitHub Desktop.
AES encryption in JavaScript
This file contains 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
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script> | |
<script> | |
//JS FIX IV ENCRYPTION CBC | |
var message = 'I love Medium'; | |
var key ='AAAAAAAAAAAAAAAA'//key used in Python | |
key = CryptoJS.enc.Utf8.parse(key); | |
var iv = CryptoJS.enc.Utf8.parse('BBBBBBBBBBBBBBBB') | |
var encrypted = CryptoJS.AES.encrypt(message, key, { iv: iv, mode: CryptoJS.mode.CBC}); | |
encrypted =encrypted.toString(); | |
console.log('encrypted',encrypted ); | |
alert(encrypted) | |
//JS RANDOM IV ENCRYPTION CBC | |
var iv = CryptoJS.enc.Hex.parse("101112131415161718191a1b1c1d1e1f"); | |
var encrypted = CryptoJS.AES.encrypt(message, key, { iv: iv, mode: CryptoJS.mode.CBC}); | |
encrypted =encrypted.toString(); | |
console.log('encrypted',encrypted ); | |
alert(encrypted) | |
//JS ENCRYPTION ECB | |
var encrypted = CryptoJS.AES.encrypt(message, key, {mode: CryptoJS.mode.ECB}); | |
encrypted =encrypted.toString(); | |
console.log('encrypted',encrypted ); | |
alert(encrypted) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment