php / php/php-src

Add streaming encryption/decryption API to OpenSSL extension (openssl_encrypt_init / openssl_encrypt_update / openssl_encrypt_final)

Aperta
#19,553 3 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@bukka ci sta già lavorando.

Dal 22/8/2025.

Extension: openssl Feature Status: Requires RFC
Lingua principale
C
Stelle
40.4k
Fork
8.2k
Merge medio
2g 13h
PR unite (30g)
96

Descrizione

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);

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.