php / php/php-src

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

オープン
#19,553 コメント 3 件 リアクション 0 件 担当者 1 名 GitHub で見る

@bukka がすでに取り組んでいます。

2025年8月22日 から。

Extension: openssl Feature Status: Requires RFC
主要言語
C
スター
40.4k
フォーク
8.1k
平均マージ
2日 13時間
マージ済み PR(30日)
96

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。