PluginProbe ʕ •ᴥ•ʔ
Transferito: WP Migration / trunk
Transferito: WP Migration vtrunk
trunk 11.4.0 12.0.0 13.1.0 14.0.0 14.0.11 14.0.7 14.1.0 14.1.1 14.1.2 14.1.3 14.1.4
transferito / vendor / aws / aws-sdk-php / src / Crypto / MaterialsProvider.php
transferito / vendor / aws / aws-sdk-php / src / Crypto Last commit date
Cipher 11 months ago Polyfill 11 months ago AbstractCryptoClient.php 11 months ago AbstractCryptoClientV2.php 11 months ago AesDecryptingStream.php 11 months ago AesEncryptingStream.php 11 months ago AesGcmDecryptingStream.php 11 months ago AesGcmEncryptingStream.php 11 months ago AesStreamInterface.php 11 months ago AesStreamInterfaceV2.php 11 months ago DecryptionTrait.php 11 months ago DecryptionTraitV2.php 11 months ago EncryptionTrait.php 11 months ago EncryptionTraitV2.php 11 months ago KmsMaterialsProvider.php 11 months ago KmsMaterialsProviderV2.php 11 months ago MaterialsProvider.php 11 months ago MaterialsProviderInterface.php 11 months ago MaterialsProviderInterfaceV2.php 11 months ago MaterialsProviderV2.php 11 months ago MetadataEnvelope.php 11 months ago MetadataStrategyInterface.php 11 months ago
MaterialsProvider.php
106 lines
1 <?php
2 namespace Aws\Crypto;
3
4 abstract class MaterialsProvider implements MaterialsProviderInterface
5 {
6 private static $supportedKeySizes = [
7 128 => true,
8 192 => true,
9 256 => true,
10 ];
11
12 /**
13 * Returns if the requested size is supported by AES.
14 *
15 * @param int $keySize Size of the requested key in bits.
16 *
17 * @return bool
18 */
19 public static function isSupportedKeySize($keySize)
20 {
21 return isset(self::$supportedKeySizes[$keySize]);
22 }
23
24 /**
25 * Performs further initialization of the MaterialsProvider based on the
26 * data inside the MetadataEnvelope.
27 *
28 * @param MetadataEnvelope $envelope A storage envelope for encryption
29 * metadata to be read from.
30 *
31 * @return MaterialsProvider
32 *
33 * @throws \RuntimeException Thrown when there is an empty or improperly
34 * formed materials description in the envelope.
35 *
36 * @internal
37 */
38 abstract public function fromDecryptionEnvelope(MetadataEnvelope $envelope);
39
40 /**
41 * Returns the material description for this Provider so it can be verified
42 * by encryption mechanisms.
43 *
44 * @return string
45 */
46 abstract public function getMaterialsDescription();
47
48 /**
49 * Returns the wrap algorithm name for this Provider.
50 *
51 * @return string
52 */
53 abstract public function getWrapAlgorithmName();
54
55 /**
56 * Takes a content encryption key (CEK) and description to return an
57 * encrypted key according to the Provider's specifications.
58 *
59 * @param string $unencryptedCek Key for use in encrypting other data
60 * that itself needs to be encrypted by the
61 * Provider.
62 * @param string $materialDescription Material Description for use in
63 * encrypting the $cek.
64 *
65 * @return string
66 */
67 abstract public function encryptCek($unencryptedCek, $materialDescription);
68
69 /**
70 * Takes an encrypted content encryption key (CEK) and material description
71 * for use decrypting the key according to the Provider's specifications.
72 *
73 * @param string $encryptedCek Encrypted key to be decrypted by the Provider
74 * for use decrypting other data.
75 * @param string $materialDescription Material Description for use in
76 * encrypting the $cek.
77 *
78 * @return string
79 */
80 abstract public function decryptCek($encryptedCek, $materialDescription);
81
82 /**
83 * @param string $keySize Length of a cipher key in bits for generating a
84 * random content encryption key (CEK).
85 *
86 * @return string
87 */
88 public function generateCek($keySize)
89 {
90 return openssl_random_pseudo_bytes($keySize / 8);
91 }
92
93 /**
94 * @param string $openSslName Cipher OpenSSL name to use for generating
95 * an initialization vector.
96 *
97 * @return string
98 */
99 public function generateIv($openSslName)
100 {
101 return openssl_random_pseudo_bytes(
102 openssl_cipher_iv_length($openSslName)
103 );
104 }
105 }
106