Skip to content Skip to sidebar Skip to footer

How Can I Encrypt A String With Aes-128-cbc Algorithm In Javascript?

I have the following shell script which uses openssl to encrypt string: API_KEY='qrBprgc/3dTjrrD@4t!9FcNjwT3_Ra' DATE='Mon, 19 Mar 2018 12:45:05 EET' aesivkey=$(echo -n '$DATE' |

Solution 1:

Currently the result is Salted__ (see the ASCII contents of the base 64 encoding, the first 8 bytes spell this word), i.e. it uses password encryption. This is probably because your key and IV need to be decoded from hexadecimals to a WordArray before use. If the key is a string instead of a WordArray it will be interpreted as being a password, and the key will be derived.

For instance:

CryptoJS.enc.Hex.parse(aes128cbckey)

and

iv: CryptoJS.enc.Hex.parse(aes128cbciv)

Notes:

  • Specifying the keySize in the configuration parameters is nice if you provide a password, but if you specify the key directly you should probably not use it.

  • The developer that created CryptoJS should really really really not have overloaded the encrypt function.

Post a Comment for "How Can I Encrypt A String With Aes-128-cbc Algorithm In Javascript?"