1

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

Hendrik
  • 71
  • 8
  • We can't help you without code, but generally **no** that can't happen. Are you maybe transmitting in hex and not decoding it back? – Artjom B. Jul 08 '15 at 17:11

1 Answers1

2

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.

erickson
  • 265,237
  • 58
  • 395
  • 493
  • That doesnt work :/ Why you find this method unsecure? – Hendrik Jul 08 '15 at 17:45
  • @Hendrik *What* doesn't work? Show your updated code and detail the current results. You are deriving a key by hashing a password once. That's not secure. I would hazard a guess that there are other problems too. – erickson Jul 08 '15 at 18:09
  • But why is a hash as a aes key unsecure? The code don't is dont needet. The problem is that every format i use is bigger then the original. Base64, Hex. I can't send it in latin1 (checksum on server failed) and when i want to format in utf-8 there comes a error "Malformed UTF-8 data". The only positive is that i know the reason now. But i have no solution for that – Hendrik Jul 09 '15 at 07:14
  • Please see [this answer about passwords.](http://stackoverflow.com/a/348140/3474) For CrypoJS use its [PBKDF2 function.](https://code.google.com/p/crypto-js/#PBKDF2) Any conversion to text is going to be longer than the original data. You have two options: don't convert to text, but send "binary" data to the server, or use Base-64 or (more space-efficient but less portable) Base-85 encoding to transform to text. Base-64 will be 133% of the original size, and Base-85 will be 125% of the original. There's no way around that expansion if you want to use text. – erickson Jul 09 '15 at 16:42