PHP code example of armen / whatsapp-psr7-streams

1. Go to this page and download the library: Download armen/whatsapp-psr7-streams library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

armen / whatsapp-psr7-streams example snippets



use Armen\WhatsappPsr7Streams\Stream\Encrypt;
use Armen\WhatsappPsr7Streams\Stream\Decrypt;
use Armen\WhatsappPsr7Streams\MediaType;
use GuzzleHttp\Psr7\Utils;
use Nyholm\Psr7\Factory\Psr17Factory;

$mediaKey = random_bytes(32);

// $originalStream = Utils::streamFor(file_get_contents('samples/IMAGE.original'));
//or
$psr17Factory = new Psr17Factory();
$originalStream = $psr17Factory->createStream(file_get_contents('samples/IMAGE.original'));

//Шифрование
$enc = new Encrypt($input, $mediaKey, MediaType::IMAGE->value);

//Дешифрование
$dec = new Decrypt($enc, $mediaKey, MediaType::IMAGE->value);

file_put_contents('samples/results/IMAGE.enc', $enc->getContents());
file_put_contents('samples/results/IMAGE.original', $dec->getContents());