W
W
wutiarn2014-03-02 08:57:57
Python
wutiarn, 2014-03-02 08:57:57

How to make CryptoJS decrypt what PyCrypto encrypts?

Good afternoon. Since no one answered my previous question (probably because of its cumbersomeness), I will try to reformulate it very clearly.
So, the task: on your own (without ssl) to organize the transfer of encrypted messages between the server (python) and the client (javascript).
Problem: I can't seem to get CryptoJS to decrypt what PyCrypto encrypts. Probably due to my handicap from birth.
So, what I have already done:
1. Tried all possible encryption modes on both sides. As a result, I came to the conclusion that ECB is an ideal option.
2. Encoded / decoded the result in base64 (for transfer).
3. Furiously buggered about the multiplicity of everything and everything 16. As a result, I googled and riveted this:

BS = 16
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
unpad = lambda s : s[0:-ord(s[-1])]

4. As a key, md5 from sha256 from the password is used (because sha256 is simply too long to be a key)
5. Encrypted (on the server side) in this case, a random number of 16 bytes. The pad/unpad functions are written for the future (will there be?)
6. Everything works perfectly in pycrypto (encrypt/decrypt). But cryptojs stubbornly does not want to decode. I tried to slip it both a base64 string and just a bunch of bytes (previously converted from base64). Useless. Simply and without errors, it returns an empty string in response.
And one more question for backfilling. The cryptojs docs mention a whole bunch of padding schemes. But I stubbornly do not see their descriptions or specifications on the Internet.
In general, if anyone has experience of torment with this - share. I will be extremely grateful.
The answer to the question "Why do you need all this??" can be found here: How to implement encryption of websocket traffic between an angular application and a python server without ssl?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maxaon, 2014-03-02
@maxaon

Try to bring encrypted messages to a common denominator. Use the console tool from the OpenSSL package to generate the underlying encrypted message. Next, encrypt the text using CryptoJS and PyCrypto so that you get the result from OpenSSL

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question