internal static EncryptionInstructions GenerateInstructionsForKMSMaterials()

in src/EncryptionUtils.cs [261:281]


        internal static EncryptionInstructions GenerateInstructionsForKMSMaterials(IAmazonKeyManagementService kmsClient, EncryptionMaterials materials)
        {
            if (materials.KMSKeyID == null)
            {
                throw new ArgumentNullException(nameof(materials.KMSKeyID), KmsKeyIdNullMessage);
            }

            var iv = new byte[IVLength];

            // Generate IV, and get both the key and the encrypted key from KMS.
            RandomNumberGenerator.Create().GetBytes(iv);
            var generateDataKeyResult = kmsClient.GenerateDataKey(new GenerateDataKeyRequest
            {
                KeyId = materials.KMSKeyID,
                EncryptionContext = materials.MaterialsDescription,
                KeySpec = KMSKeySpec
            });

            return new EncryptionInstructions(materials.MaterialsDescription, generateDataKeyResult.Plaintext.ToArray(), generateDataKeyResult.CiphertextBlob.ToArray(), iv,
                XAmzWrapAlgKmsValue, XAmzAesCbcPaddingCekAlgValue);
        }