brix / crypto-js

JavaScript library of crypto standards.
Other
15.83k stars 2.39k forks source link

Implement CryptoJS to decrypt/encrypt as https://www.devglan.com/online-tools/aes-encryption-decryption #200

Open fedika opened 5 years ago

fedika commented 5 years ago

Hi CryptoJS,

So I'm trying to make a program which able to encrypt/decrypt as https://www.devglan.com/online-tools/aes-encryption-decryption works. But I have a problem here with my work which it returns invalid value when I applied CryptoJS.

Here my work:

    const encryptedString = 'mzyNiHkzVf3UpIYBkPFT1w==';

    const ciphertext = await CryptoJS.AES.decrypt(encryptedString, 'devtester@2018!!', {
      mode: CryptoJS.mode.ECB,
      keySize: 128,
    });
    console.log(JSON.stringify(ciphertext.toString(CryptoJS.enc.Base64)));

log show error 'RangeError: Invalid array length' while on the site could return valid value as shown https://ibb.co/pRDrm4P

Did I make mistake? I really appreciate for the insight.

Thank you

radharajendran commented 4 years ago

const encryptedString = 'mzyNiHkzVf3UpIYBkPFT1w=='; let keyUtf8 = CryptoJS.enc.Utf8.parse('devtester@2018!!')

const ciphertext = await CryptoJS.AES.decrypt(encryptedString, keyUtf8, { mode: CryptoJS.mode.ECB, keySize: 128, });

ciphertext = CryptoJS.enc.Utf8.stringify(ciphertext).toString();

When converting key to UTF8 array buffer issue resolved