MaterialsProviderV2.php 2.0 KB

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