PluginProbe
Media Cloud Sync / 1.4.2
Media Cloud Sync v1.4.2
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.4.2, at includes/sdk/s3/Aws/Crypto/AesGcmDecryptingStream.php

73 lines 2.1 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 /**
10 * @internal Represents a stream of data to be gcm decrypted.
11 */
12 class AesGcmDecryptingStream implements AesStreamInterface
13 {
14 use StreamDecoratorTrait;
15 private $aad;
16 private $initializationVector;
17 private $key;
18 private $keySize;
19 private $cipherText;
20 private $tag;
21 private $tagLength;
22 /**
23 * @var StreamInterface
24 */
25 private $stream;
26 /**
27 * @param StreamInterface $cipherText
28 * @param string $key
29 * @param string $initializationVector
30 * @param string $tag
31 * @param string $aad
32 * @param int $tagLength
33 * @param int $keySize
34 */
35 public function __construct(StreamInterface $cipherText, $key, $initializationVector, $tag, $aad = '', $tagLength = 128, $keySize = 256)
36 {
37 $this->cipherText = $cipherText;
38 $this->key = $key;
39 $this->initializationVector = $initializationVector;
40 $this->tag = $tag;
41 $this->aad = $aad;
42 $this->tagLength = $tagLength;
43 $this->keySize = $keySize;
44 // unsetting the property forces the first access to go through
45 // __get().
46 unset($this->stream);
47 }
48 public function getOpenSslName()
49 {
50 return "aes-{$this->keySize}-gcm";
51 }
52 public function getAesName()
53 {
54 return 'AES/GCM/NoPadding';
55 }
56 public function getCurrentIv()
57 {
58 return $this->initializationVector;
59 }
60 public function createStream()
61 {
62 $result = \openssl_decrypt((string) $this->cipherText, $this->getOpenSslName(), $this->key, \OPENSSL_RAW_DATA, $this->initializationVector, $this->tag, $this->aad);
63 if ($result === \false) {
64 throw new CryptoException('The requested object could not be ' . 'decrypted due to an invalid authentication tag.');
65 }
66 return Psr7\Utils::streamFor($result);
67 }
68 public function isWritable() : bool
69 {
70 return \false;
71 }
72 }
73