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

14,114

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.

Share:
14,114
jnbdz
Author by

jnbdz

Updated on June 05, 2022

Comments

  • jnbdz
    jnbdz almost 2 years

    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?