Problems with AES in crypto-js and pycrypto

I am trying to implement a connection between

On the server side of python, I encrypt the string with ivand passphraseand send iv with base64 encrypted text encoded on the client side javascript. Then I want a decryptline with a passphrase that 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" 
        src="http://crypto-js.googlecode.com/files/2.5.3-crypto-sha1-hmac-pbkdf2-blockmodes-aes.js">
   </script>
// 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});

In this example, I get a javascript error

Uncaught URIError: URI malformed

But this is just one example - I tried all the base64 encoding / decoding constellations that I could think of. I also tried changing the mode. But these are all random tests, and I want to understand what I really need to do.

  • What encoding does crypt require?
  • ?
  • -, python?
  • ? ?
  • javascript, ?

reagards, samuirai

+3
1

, base64, iv encrypted_text:

encrypted_text = base64.b64encode(iv + aes.encrypt("this is a test.."))

(https://www.dlitz.net/software/pycrypto/doc/):

:

from Crypto.Cipher import AES
from Crypto import Random

key = b'Sixteen byte key'
iv = Random.new().read(AES.block_size)
cipher = AES.new(key, AES.MODE_CFB, iv)
msg = iv + cipher.encrypt(b'Attack at dawn')
0

All Articles