mirror of
https://github.com/SociallyDev/Spaces-API.git
synced 2025-08-14 02:27:23 -07:00
spaces.php
This commit is contained in:
parent
7755490b81
commit
eefa32741e
845 changed files with 50409 additions and 0 deletions
101
aws/Aws/Crypto/AesGcmEncryptingStream.php
Normal file
101
aws/Aws/Crypto/AesGcmEncryptingStream.php
Normal file
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
namespace Aws\Crypto;
|
||||
|
||||
use GuzzleHttp\Psr7;
|
||||
use GuzzleHttp\Psr7\StreamDecoratorTrait;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use \RuntimeException;
|
||||
|
||||
/**
|
||||
* @internal Represents a stream of data to be gcm encrypted.
|
||||
*/
|
||||
class AesGcmEncryptingStream implements AesStreamInterface
|
||||
{
|
||||
use StreamDecoratorTrait;
|
||||
|
||||
private $aad;
|
||||
|
||||
private $initializationVector;
|
||||
|
||||
private $key;
|
||||
|
||||
private $keySize;
|
||||
|
||||
private $plaintext;
|
||||
|
||||
private $tag = '';
|
||||
|
||||
private $tagLength;
|
||||
|
||||
/**
|
||||
* @param StreamInterface $plaintext
|
||||
* @param string $key
|
||||
* @param string $initializationVector
|
||||
* @param string $aad
|
||||
* @param int $tagLength
|
||||
* @param int $keySize
|
||||
*/
|
||||
public function __construct(
|
||||
StreamInterface $plaintext,
|
||||
$key,
|
||||
$initializationVector,
|
||||
$aad = '',
|
||||
$tagLength = 16,
|
||||
$keySize = 256
|
||||
) {
|
||||
if (version_compare(PHP_VERSION, '7.1', '<')) {
|
||||
throw new RuntimeException(
|
||||
'AES-GCM decryption is only supported in PHP 7.1 or greater'
|
||||
);
|
||||
}
|
||||
|
||||
$this->plaintext = $plaintext;
|
||||
$this->key = $key;
|
||||
$this->initializationVector = $initializationVector;
|
||||
$this->aad = $aad;
|
||||
$this->tagLength = $tagLength;
|
||||
$this->keySize = $keySize;
|
||||
}
|
||||
|
||||
public function getOpenSslName()
|
||||
{
|
||||
return "aes-{$this->keySize}-gcm";
|
||||
}
|
||||
|
||||
public function getAesName()
|
||||
{
|
||||
return 'AES/GCM/NoPadding';
|
||||
}
|
||||
|
||||
public function getCurrentIv()
|
||||
{
|
||||
return $this->initializationVector;
|
||||
}
|
||||
|
||||
public function createStream()
|
||||
{
|
||||
return Psr7\stream_for(openssl_encrypt(
|
||||
(string) $this->plaintext,
|
||||
$this->getOpenSslName(),
|
||||
$this->key,
|
||||
OPENSSL_RAW_DATA,
|
||||
$this->initializationVector,
|
||||
$this->tag,
|
||||
$this->aad,
|
||||
$this->tagLength
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTag()
|
||||
{
|
||||
return $this->tag;
|
||||
}
|
||||
|
||||
public function isWritable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue