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 / AesGcmEncryptingStream.php

AesGcmEncryptingStream.php in Media Cloud Sync 1.4.2, at includes/sdk/s3/Aws/Crypto/AesGcmEncryptingStream.php

88 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\GuzzleHttp\Psr7;
6 use Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7\StreamDecoratorTrait;
7 use Dudlewebs\WPMCS\s3\Psr\Http\Message\StreamInterface;
8 /**
9 * @internal Represents a stream of data to be gcm encrypted.
10 */
11 class AesGcmEncryptingStream implements AesStreamInterface, AesStreamInterfaceV2
12 {
13 use StreamDecoratorTrait;
14 private $aad;
15 private $initializationVector;
16 private $key;
17 private $keySize;
18 private $plaintext;
19 private $tag = '';
20 private $tagLength;
21 /**
22 * @var StreamInterface
23 */
24 private $stream;
25 /**
26 * Same as non-static 'getAesName' method, allowing calls in a static
27 * context.
28 *
29 * @return string
30 */
31 public static function getStaticAesName()
32 {
33 return 'AES/GCM/NoPadding';
34 }
35 /**
36 * @param StreamInterface $plaintext
37 * @param string $key
38 * @param string $initializationVector
39 * @param string $aad
40 * @param int $tagLength
41 * @param int $keySize
42 */
43 public function __construct(StreamInterface $plaintext, $key, $initializationVector, $aad = '', $tagLength = 16, $keySize = 256)
44 {
45 $this->plaintext = $plaintext;
46 $this->key = $key;
47 $this->initializationVector = $initializationVector;
48 $this->aad = $aad;
49 $this->tagLength = $tagLength;
50 $this->keySize = $keySize;
51 // unsetting the property forces the first access to go through
52 // __get().
53 unset($this->stream);
54 }
55 public function getOpenSslName()
56 {
57 return "aes-{$this->keySize}-gcm";
58 }
59 /**
60 * Same as static method and retained for backwards compatibility
61 *
62 * @return string
63 */
64 public function getAesName()
65 {
66 return self::getStaticAesName();
67 }
68 public function getCurrentIv()
69 {
70 return $this->initializationVector;
71 }
72 public function createStream()
73 {
74 return Psr7\Utils::streamFor(\openssl_encrypt((string) $this->plaintext, $this->getOpenSslName(), $this->key, \OPENSSL_RAW_DATA, $this->initializationVector, $this->tag, $this->aad, $this->tagLength));
75 }
76 /**
77 * @return string
78 */
79 public function getTag()
80 {
81 return $this->tag;
82 }
83 public function isWritable() : bool
84 {
85 return \false;
86 }
87 }
88