CryptoJS AES Increase File Size

2019-08-04 19:15发布

问题:

Thank you for your help.

I have a problem with sjcl library or cryptojs aes library. Everytime i encrypt my file with aes the file size is * 2. For example: When i upload a 4mb file then there is a 8mb file on my server.

I split the file on block which bytesize can be divided by 16.

Please help me

This is the way i encrypt the file:

var l_EncryptetData = CryptoJS.AES.encrypt(p_ChunkData, p_FileKey).toString();

And this is a example array with block sizes from the 4mb file:

0: 1572864
1: 1572864
2: 867005
length: 3

And the FileKey is a SHA-256 Hash

回答1:

You are converting the cipher output (a CipherParams object) to a character string. By default, CryptoJS does this by representing the result in hexadecimal, where each byte is encoded as two hex digits. You can override this behavior by providing a custom format strategy. Or better yet, don't convert the cipher text to a character string; keep it as binary data.

Please warn users of your application that it is not secure.