3
$\begingroup$

I'm trying to use PHP to encrypt files with a public key. I'm using the function openssl_seal that "encrypts data by using RC4 with a randomly generated secret key."

RC4 is considered unsafe so the alternative is to use AES ECB, but it too is generally considered unsafe (AES CBC is sadly not an option).

My question is: Is AES ECB still unsafe, even when used with a randomly generated key, which is different for each file?

$\endgroup$
  • $\begingroup$ Why is CBC not an option? I don't see that limitation in the API... $\endgroup$ – Maarten Bodewes Aug 22 '15 at 14:06
  • 1
    $\begingroup$ It's not documented, but all CBC ciphers fail, I suspect because there is no parameter for initialization vector and therefore they cannot work. $\endgroup$ – SimZal Aug 22 '15 at 16:01
  • $\begingroup$ @SimZal, did you try OFB or CFB? If the lack of IV is the reason, they may fail as well, of course. $\endgroup$ – otus Aug 22 '15 at 16:34
  • $\begingroup$ @otus I've tested AES OFB and CFB and they both fail. It is the same if I try Blowfish - ECB works, while CBC, OFB and CFB fail. $\endgroup$ – SimZal Aug 22 '15 at 16:53
  • $\begingroup$ @SimZal, ok, too bad. $\endgroup$ – otus Aug 22 '15 at 16:55
4
$\begingroup$

ECB is not secure even with per file keys, because if two blocks of the file are identical, this is visible in the ciphertext. The only * cases where ECB is secure is encrypting completely random data or encrypting a single block per key.

You should pick something more secure if your can help it.

If there is literally no other option than RC4 and AES ECB, you could use first RC4 and then AES ECB. RC4 would make it almost random and AES ECB would hide the biases. However, general concerns with cascaded ciphers would apply.

* Ok, fine, or if plaintext blocks are known to be unique, but that's rare and not the case here.

$\endgroup$
  • $\begingroup$ Thanks, that's a useful answer. I guess I will have to avoid the openssl_seal function to be able to use AES CBC. It's a shame that they let this function stay unsafe, PHP is quite a popular language. $\endgroup$ – SimZal Aug 22 '15 at 16:07
  • $\begingroup$ You should also consider using libsodium instead. Specifically \Sodium\crypto_box_seal(). $\endgroup$ – Scott Arciszewski Nov 8 '15 at 0:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.