PluginProbe
Media Cloud Sync / 1.4.1
Media Cloud Sync v1.4.1
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 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / s3 / Aws / Crypto / MaterialsProvider.php

MaterialsProvider.php in Media Cloud Sync 1.4.1, at includes/sdk/s3/Aws/Crypto/MaterialsProvider.php

93 lines 3.2 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 abstract class MaterialsProvider implements MaterialsProviderInterface
6 {
7 private static $supportedKeySizes = [128 => \true, 192 => \true, 256 => \true];
8 /**
9 * Returns if the requested size is supported by AES.
10 *
11 * @param int $keySize Size of the requested key in bits.
12 *
13 * @return bool
14 */
15 public static function isSupportedKeySize($keySize)
16 {
17 return isset(self::$supportedKeySizes[$keySize]);
18 }
19 /**
20 * Performs further initialization of the MaterialsProvider based on the
21 * data inside the MetadataEnvelope.
22 *
23 * @param MetadataEnvelope $envelope A storage envelope for encryption
24 * metadata to be read from.
25 *
26 * @return MaterialsProvider
27 *
28 * @throws \RuntimeException Thrown when there is an empty or improperly
29 * formed materials description in the envelope.
30 *
31 * @internal
32 */
33 public abstract function fromDecryptionEnvelope(MetadataEnvelope $envelope);
34 /**
35 * Returns the material description for this Provider so it can be verified
36 * by encryption mechanisms.
37 *
38 * @return string
39 */
40 public abstract function getMaterialsDescription();
41 /**
42 * Returns the wrap algorithm name for this Provider.
43 *
44 * @return string
45 */
46 public abstract function getWrapAlgorithmName();
47 /**
48 * Takes a content encryption key (CEK) and description to return an
49 * encrypted key according to the Provider's specifications.
50 *
51 * @param string $unencryptedCek Key for use in encrypting other data
52 * that itself needs to be encrypted by the
53 * Provider.
54 * @param string $materialDescription Material Description for use in
55 * encrypting the $cek.
56 *
57 * @return string
58 */
59 public abstract function encryptCek($unencryptedCek, $materialDescription);
60 /**
61 * Takes an encrypted content encryption key (CEK) and material description
62 * for use decrypting the key according to the Provider's specifications.
63 *
64 * @param string $encryptedCek Encrypted key to be decrypted by the Provider
65 * for use decrypting other data.
66 * @param string $materialDescription Material Description for use in
67 * encrypting the $cek.
68 *
69 * @return string
70 */
71 public abstract function decryptCek($encryptedCek, $materialDescription);
72 /**
73 * @param string $keySize Length of a cipher key in bits for generating a
74 * random content encryption key (CEK).
75 *
76 * @return string
77 */
78 public function generateCek($keySize)
79 {
80 return \openssl_random_pseudo_bytes($keySize / 8);
81 }
82 /**
83 * @param string $openSslName Cipher OpenSSL name to use for generating
84 * an initialization vector.
85 *
86 * @return string
87 */
88 public function generateIv($openSslName)
89 {
90 return \openssl_random_pseudo_bytes(\openssl_cipher_iv_length($openSslName));
91 }
92 }
93