Add streaming encryption/decryption API to OpenSSL extension (openssl_encrypt_init / openssl_encrypt_update / openssl_encrypt_final)
Ouverte
@bukka y travaille déjà.
Depuis le 22/8/2025.
Extension: openssl
Feature
Status: Requires RFC
- Langage dominant
- C
- Étoiles
- 40.4k
- Forks
- 8.1k
- Merge moyen
- 2 j 13 h
- PR mergées (30 j)
- 96
Description
Description
Currently, the OpenSSL extension in PHP provides openssl_encrypt() and openssl_decrypt(), which require the entire data buffer in memory for AES-128-GCM, AES-256-GCM... This makes it impractical to process very large files (e.g. 100 MB, 1 GB, 1 TB) because PHP will try to load the entire content into memory before encrypting/decrypting.
Proposal
Introduce a streaming API for encryption/decryption, similar to how hash_init(), hash_update(), and hash_final() work.
For example for encryption:
$res = openssl_encrypt_init('aes-256-gcm', $key, OPENSSL_RAW_DATA, $iv, $tag_length);
openssl_encrypt_update($ctx, $aad);
while (!feof($fp_in)) {
$chunk = fread($fp_in, 1048576); // 1 MB
$enc = openssl_encrypt_update($res, $chunk);
fwrite($fp_out, $enc);
}
$enc = openssl_encrypt_final($res, $tag);
fwrite($fp_out, $enc);
And for decryption:
$res = openssl_decrypt_init("aes-256-gcm", $key, OPENSSL_RAW_DATA, $iv, $tag);
openssl_decrypt_update($ctx, $aad);
while (!feof($fp_in)) {
$chunk = fread($fp_in, 1048576);
$dec = openssl_decrypt_update($res, $chunk);
fwrite($fp_out, $dec);
}
$dec = openssl_decrypt_final($res);
fwrite($fp_out, $dec);
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Évaluation
Cette issue n'a pas encore été évaluée.