I try to implement a communication between

On the python server side I encrypt a string with an iv and a passphrase and send the iv with the encrypted text base64 encoded to the javascript client side. Then I want to decrypt the string with the passphrase the user can enter.

python – server

from Crypto.Cipher import AES
from Crypto import Random

iv = Random.get_random_bytes(16)
key = "1234567812345678"
aes = AES.new(key, AES.MODE_CFB, iv)
encrypted_text = base64.b64encode(aes.encrypt("this is a test.."))
iv = base64.b64encode(iv)
# send iv, encrypted_text to client

javascript – client

// <script type="text/javascript" 
// text, and iv is base64encoded from the python script
// key is a string from an <input type='text'>
decrypted = Crypto.AES.decrypt(text, key, {iv: iv, mode: new Crypto.mode.CFB});

With this example I get a javascript error

Uncaught URIError: URI malformed

But this is just one example – I tried every constellation of base64 encodings/decodings I could think of. I also tried to changed the Mode. But these are all random tests and I want to understand what I really have to do.

  • What encoding does the crypt-js want?
  • Which mode should I chose?
  • Is there something I should change on the python server side?
  • what is about padding? Could there be the fault?
  • any other javascript libraries you can recommend?

thank you very much and kind reagards,