PluginProbe
Media Cloud Sync / 1.2.10
Media Cloud Sync v1.2.10
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
media-cloud-sync / includes / sdk / s3 / Aws / Crypto / AesGcmDecryptingStream.php

AesGcmDecryptingStream.php in Media Cloud Sync 1.2.10, at includes/sdk/s3/Aws/Crypto/AesGcmDecryptingStream.php

72 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\Aws\Crypto;
4
5 use Dudlewebs\WPMCS\s3\Aws\Exception\CryptoException;
6 use Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7;
7 use Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7\StreamDecoratorTrait;
8 use Dudlewebs\WPMCS\s3\Psr\Http\Message\StreamInterface;
9 use Dudlewebs\WPMCS\s3\Aws\Crypto\Polyfill\AesGcm;
10 use Dudlewebs\WPMCS\s3\Aws\Crypto\Polyfill\Key;
11 /**
12 * @internal Represents a stream of data to be gcm decrypted.
13 */
14 class AesGcmDecryptingStream implements AesStreamInterface
15 {
16 use StreamDecoratorTrait;
17 private $aad;
18 private $initializationVector;
19 private $key;
20 private $keySize;
21 private $cipherText;
22 private $tag;
23 private $tagLength;
24 /**
25 * @param StreamInterface $cipherText
26 * @param string $key
27 * @param string $initializationVector
28 * @param string $tag
29 * @param string $aad
30 * @param int $tagLength
31 * @param int $keySize
32 */
33 public function __construct(StreamInterface $cipherText, $key, $initializationVector, $tag, $aad = '', $tagLength = 128, $keySize = 256)
34 {
35 $this->cipherText = $cipherText;
36 $this->key = $key;
37 $this->initializationVector = $initializationVector;
38 $this->tag = $tag;
39 $this->aad = $aad;
40 $this->tagLength = $tagLength;
41 $this->keySize = $keySize;
42 }
43 public function getOpenSslName()
44 {
45 return "aes-{$this->keySize}-gcm";
46 }
47 public function getAesName()
48 {
49 return 'AES/GCM/NoPadding';
50 }
51 public function getCurrentIv()
52 {
53 return $this->initializationVector;
54 }
55 public function createStream()
56 {
57 if (\version_compare(\PHP_VERSION, '7.1', '<')) {
58 return Psr7\Utils::streamFor(AesGcm::decrypt((string) $this->cipherText, $this->initializationVector, new Key($this->key), $this->aad, $this->tag, $this->keySize));
59 } else {
60 $result = \openssl_decrypt((string) $this->cipherText, $this->getOpenSslName(), $this->key, \OPENSSL_RAW_DATA, $this->initializationVector, $this->tag, $this->aad);
61 if ($result === \false) {
62 throw new CryptoException('The requested object could not be' . ' decrypted due to an invalid authentication tag.');
63 }
64 return Psr7\Utils::streamFor($result);
65 }
66 }
67 public function isWritable()
68 {
69 return \false;
70 }
71 }
72