Skip to content Skip to sidebar Skip to footer

Aes - Crypto Js & Php

I've problem with decryption data encrypted in cryptojs. Sometimes it works sometimes not, if works it returns 'Message', but if dosent it returns garbage. var salt = CryptoJS.

Solution 1:

You shouldn't rtrim the key. The key may contain any byte value, including the ones you just trimmed away. Older versions happily fill the key up with 0 valued bytes, so that means that the key may differ from the one used in the CryptoJS source.

Sending the key with the ciphertext doesn't make sense. Instead it is best to use PBKDF2 in PHP as well and calculate the key from a password.

Finally, note that PHP mcrypt defaults to zero padding, unpad using PKCS#7 instead. The comments for mcrypt on the help pages contain a good PKCS#7 implementation to perform the unpadding.

Post a Comment for "Aes - Crypto Js & Php"