0

I have some JSON data that I need to encrypt before sending it to the client side. I can encrypt the data using pycrpto like this:

from Crypto.Cipher import AES
key = '0123456789abcdef'
mode = AES.MODE_CBC
encryptor = AES.new(key, mode)
text = jsonData
ciphertext = encryptor.encrypt(text)

And then I can send it to the client side. Now I need to use jQuery/Javascript to convert the ciphertext to plain text. jsaes is an implementation of AES in Javascript. Can it be used to decrypt data back to plain text? Or is there any other library I can use to complete this task?

2 Answers 2

2

Your straight forward answer is what Wes said.

However, there are problems of transmitting the key securely. (One could use a private/public key mechanism but then, there's no point encrypting the data because you already a P/P mechanism)

SSL/HTTPS were created for secure "transactions" between client and server, I would advise you use those.

Sign up to request clarification or add additional context in comments.

3 Comments

With the current formulation this is more of a comment. I'd reformulate it a bit, so it's more of an answer.
@CodeInChaos OK - re-writing now.
I would give you a +1 for your answer.
1

You should be able to decrypt it using any implementation of AES, just make sure you use the same mode that you used to encrypt it (in this case Cipher Block Chain or CBC)

http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29

Also PyCrypto, while good, might be a little bit too low level for you. You might want to look at using something like GPGME for Python: http://pyme.sourceforge.net/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.