2
votes

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:

CryptoJS.AES.decrypt(
  "Mc6prldI+uuh5Ko=",
  CryptoJS.enc.Hex.parse("0123456789abcdef0123456789abcdef"),
  { 
    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?

2

2 Answers

1
votes

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 });
0
votes

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 });