Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to encrypt files in AES-256 with PHP? [closed]

I found some tutorials online that could help but I am not sure there the best options. I would like to encrypt the file with a highly secure algorithm (I am a bit paranoid) but at the same time I am looking for speed (I know it's a bit of a contradiction)... So I chose AES-256... But what is the best way to use AES-256 with PHP to encrypt files?

like image 981
jnbdz Avatar asked Nov 18 '11 20:11

jnbdz


People also ask

What is better than 256-bit AES encryption?

The AES-256 key schedule transforms a 256-bit secret key into fourteen 128-bit rounds keys. Of the two, the AES-128 key schedule is actually more secure. The AES-256 key schedule has known weaknesses that might make it possible to perform related key attacks against the algorithm.

Is AES 256 encryption end to end?

End-to-end encryption works in two different ways: symmetric or asymmetric. Symmetric encryption encodes data and offers the greatest possible security through AES-256 encryption. However, this also requires the AES-256 key itself to be transmitted securely and confidentially.


1 Answers

PHP 5.x and 7.0.x

For a symmetric algorithm, use Mcrypt.

Note though that it can be risky, from a security perspective, to use that library without knowing what everything does. Take a look at some ready-made solutions.

(Incidentally, the ciphers supported are here).

PHP 7.1.x+

The Mcrypt extension was deprecated in 7.1 and removed in 7.2, so you will need an alternative. Use Sodium instead.

like image 124
halfer Avatar answered Oct 17 '22 12:10

halfer