garsaud/cryptstreamaes

Encrypt and decrypt php resources (streams) on-the-fly using AES 128, 192, 256

v1.0.0 2023-02-20 21:47 UTC

This package is auto-updated.

Last update: 2024-11-21 10:17:38 UTC


README

GitHub CI

This package encrypts and decrypts resources (streams) using AES 128, 192 or 256 using mcrypt.

It operates on resources (local or remote obtained via fopen(…)) in chunks, making it possible to process very large contents without exceeding the memory limit.

Installation

composer require garsaud/cryptstreamaes

Usage

use Garsaud\CryptStreamAES\AES;
use Garsaud\CryptStreamAES\Length;

$aes = new AES(Length::AES256);

$aes->encrypt(
    key: 'B374A26A71490437AA024E4FADD5B497FDFF1A8EA6FF12F6FB65AF2720B59CCF',
    inputStream: fopen('myfile.jpg', 'rb'),
    outputStream: fopen('myfile-encrypted.bin', 'wb'),
);
use Garsaud\CryptStreamAES\AES;
use Garsaud\CryptStreamAES\Length;

$aes = new AES(Length::AES256);

$aes->decrypt(
    key: 'B374A26A71490437AA024E4FADD5B497FDFF1A8EA6FF12F6FB65AF2720B59CCF',
    inputStream: fopen('myfile-encrypted.bin', 'rb'),
    outputStream: fopen('myfile.jpg', 'wb'),
);