1 |
efrain |
1 |
<?php
|
|
|
2 |
namespace Aws\Crypto;
|
|
|
3 |
|
|
|
4 |
abstract class MaterialsProviderV2 implements MaterialsProviderInterfaceV2
|
|
|
5 |
{
|
|
|
6 |
private static $supportedKeySizes = [
|
|
|
7 |
128 => true,
|
|
|
8 |
256 => true,
|
|
|
9 |
];
|
|
|
10 |
|
|
|
11 |
/**
|
|
|
12 |
* Returns if the requested size is supported by AES.
|
|
|
13 |
*
|
|
|
14 |
* @param int $keySize Size of the requested key in bits.
|
|
|
15 |
*
|
|
|
16 |
* @return bool
|
|
|
17 |
*/
|
|
|
18 |
public static function isSupportedKeySize($keySize)
|
|
|
19 |
{
|
|
|
20 |
return isset(self::$supportedKeySizes[$keySize]);
|
|
|
21 |
}
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* Returns the wrap algorithm name for this Provider.
|
|
|
25 |
*
|
|
|
26 |
* @return string
|
|
|
27 |
*/
|
|
|
28 |
abstract public function getWrapAlgorithmName();
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* Takes an encrypted content encryption key (CEK) and material description
|
|
|
32 |
* for use decrypting the key according to the Provider's specifications.
|
|
|
33 |
*
|
|
|
34 |
* @param string $encryptedCek Encrypted key to be decrypted by the Provider
|
|
|
35 |
* for use decrypting other data.
|
|
|
36 |
* @param string $materialDescription Material Description for use in
|
|
|
37 |
* decrypting the CEK.
|
|
|
38 |
* @param string $options Options for use in decrypting the CEK.
|
|
|
39 |
*
|
|
|
40 |
* @return string
|
|
|
41 |
*/
|
|
|
42 |
abstract public function decryptCek($encryptedCek, $materialDescription, $options);
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
* @param string $keySize Length of a cipher key in bits for generating a
|
|
|
46 |
* random content encryption key (CEK).
|
|
|
47 |
* @param array $context Context map needed for key encryption
|
|
|
48 |
* @param array $options Additional options to be used in CEK generation
|
|
|
49 |
*
|
|
|
50 |
* @return array
|
|
|
51 |
*/
|
|
|
52 |
abstract public function generateCek($keySize, $context, $options);
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* @param string $openSslName Cipher OpenSSL name to use for generating
|
|
|
56 |
* an initialization vector.
|
|
|
57 |
*
|
|
|
58 |
* @return string
|
|
|
59 |
*/
|
|
|
60 |
public function generateIv($openSslName)
|
|
|
61 |
{
|
|
|
62 |
return openssl_random_pseudo_bytes(
|
|
|
63 |
openssl_cipher_iv_length($openSslName)
|
|
|
64 |
);
|
|
|
65 |
}
|
|
|
66 |
}
|