0

I am trying to decrypt a file in python which was encrypted using CryptoJS(AES) in Node.js. I know there is an equivalent module in python (Pycrypto) but I don't know how to use it or which mode of AES decryption to use for decrypting the data(I have the cipher and the key but don't have any iv).
Here is the code(Node.js) which i am trying to translate to Python:

  function fileEncrypt(plaintext, password){        
     return CryptoJS.AES.encrypt(plaintext,password).toString();

}
function fileDecrypt(ciphertext, password){     
    return CryptoJS.AES.decrypt(ciphertext,password).toString(CryptoJS.enc.Latin1);     
}   

As you can see, no iv has been passed here. Please help me translate the code to Python. Thank you in advance :)

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
  • Note that the cryptoJS generates both the IV and the key for you from the password you pass. The password you pass to cryptoJS is not used as the Key for AES. – Malice Aug 11 '17 at 07:06
  • https://stackoverflow.com/questions/16600509/aes-encrypt-in-cryptojs-and-decrypt-in-coldfusion – Malice Aug 11 '17 at 07:06
  • So how do I derive the key and iv in python from my password ? I am totally new to cryptography and hence have no idea about these – Suparno Sarkar Aug 11 '17 at 07:26
  • Do you need them to be compatible, as in a file encrypted by your node-script to be decrypted by the python script then you will need to extract the IV and stuff. Else you can generate a random IV and use it – Malice Aug 11 '17 at 09:16
  • https://stackoverflow.com/questions/12524994/encrypt-decrypt-using-pycrypto-aes-256 – Malice Aug 11 '17 at 09:16
  • I need to extract the key and iv. How do i do that ? – Suparno Sarkar Aug 11 '17 at 12:00
  • 1
    Possible duplicate of [How to decrypt password from JavaScript CryptoJS.AES.encrypt(password, passphrase) in Python](https://stackoverflow.com/questions/36762098/how-to-decrypt-password-from-javascript-cryptojs-aes-encryptpassword-passphras) – Artjom B. Aug 11 '17 at 17:08

0 Answers0