dllglishaoyi / crypto-js

Automatically exported from code.google.com/p/crypto-js
0 stars 0 forks source link

crypto-js is not compatible with openssl base64 encoding when decrypting with AES/CBC #38

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
If you encrypt data with the following openssl command line:

   openssl enc -aes-256-cbc -e -in foo.txt -out foo.txt.enc -pass pass:"Secret Passphrase" -base64

And attempt to decrypt the contents of foo.txt.enc with:

   CryptoJS.AES.decrypt(buffer, "Secret Passphrase");

The result is empty.  The reason appears to be because of the newline character 
in the base64-encoded output (of openssl).  If you remove the newline, such 
that the entire base64 encoding is on a single line, then CryptoJS.AES.decrypt 
works fine.

The documentation suggests that CryptoJS.AES is compatible with openssl.  I'm 
using version 1.0.1 14 Mar 2012 of openssl.

What steps will reproduce the problem?
1. Encrypt a message with the above openssl command line that is long enough to 
cause openssl to break the base64-encoding into two (or more?) lines.  I used 
the message "This is a test of the emergency broadcast system.\n".
2. Use CryptoJS.AES.decrypt(message, "Secret Passphrase") to compute the 
plaintext.
3. Note that the resulting value is empty and not the original text.
4. Remove the newlines from the base64-encoded output of openssl.
5. Repeat step 2.
6. Note that the plaintext is as expected.

I'm using CryptoJS v3.0.1. Browser is Firefox 12.  Operating system is Mac OS X 
10.7.4.

Original issue reported on code.google.com by e...@swenson.org on 21 May 2012 at 9:10

GoogleCodeExporter commented 8 years ago
Attached is a simple HTML file that demonstrates the problem.  It decrypts the 
encrypted base64, first without a line break, and secondly with a line break 
(such as openssl introduces).  It logs to the console log its results and debug 
info.  -- Eric

Original comment by e...@swenson.org on 21 May 2012 at 9:28

Attachments:

GoogleCodeExporter commented 8 years ago

Original comment by Jeff.Mott.OR on 21 May 2012 at 10:09

GoogleCodeExporter commented 8 years ago

Original comment by Jeff.Mott.OR on 25 May 2012 at 7:48

GoogleCodeExporter commented 8 years ago
I'm experiencing this exact problem in 3.1.2.  The status on this says "fixed". 
 What version was this fixed in?

Original comment by mbal...@gmail.com on 22 Mar 2013 at 7:02

GoogleCodeExporter commented 8 years ago
UTF-8 decoding failing for me too on AES. I can encode but decode fails.  Going 
ot verison 3.0.2 resolves the problem.

Original comment by stephen....@gmail.com on 20 Nov 2013 at 9:44

GoogleCodeExporter commented 8 years ago
If this is still causing people problems, use the -A option AS WELL as the 
-base64 option to suppress newline characters in the output

Original comment by evilqu...@gmail.com on 24 Jan 2014 at 3:16

GoogleCodeExporter commented 8 years ago
but that doesn't solve the problem.  Basically a minor version change broke 
compatibility.  People aren't always LITERALLY using just the command line one 
library to do this ;)

Original comment by stephen....@gmail.com on 24 Jan 2014 at 3:19