Using CryptoJS for decryption after OpenSSL encryption

I am using OpenSSL to encrypt a txt file, with "Hello World" inside, using the following command at the terminal:

openssl enc -aes-128-ctr -in file.txt -out file-out-64.txt -base64 -A
-K 0123456789abcdef0123456789abcdef -iv 00000000000000000000000000000000`

So, I am using AES-128 (CTR mode) with that dummy key and IV and generating a base64 at the end, producing the following output: Mc6prldI+uuh5Ko=

I want to decrypt this with CryptoJS and I am using the following code:

    iv   : CryptoJS.enc.Hex.parse("00000000000000000000000000000000"),
    mode : CryptoJS.mode.CTR 

I was expecting "Hello World" output but it's producing an empty string result. Can anybody help?



I found the solution. In the options parameter I had to add padding with NoPadding

var decoded   = CryptoJS.AES.decrypt("Mc6prldI+uuh5Ko=", CryptoJS.enc.Hex.parse("0123456789abcdef0123456789abcdef"), { iv: CryptoJS.enc.Hex.parse("00000000000000000000000000000000"), padding: CryptoJS.pad.NoPadding, mode: CryptoJS.mode.CTR });

Tried this?

var decrypt = CryptoJS.AES.decrypt(CryptoJS.enc.Base64.parse("Mc6prldI+uuh5Ko="), CryptoJS.enc.Hex.parse("0123456789abcdef0123456789abcdef"), { iv: CryptoJS.enc.Hex.parse("00000000000000000000000000000000"), mode: CryptoJS.mode.CTR });


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.