Amazon.S3.Encryption.EncryptionUtils.BuildInstructionsFromObjectMetadata C# (CSharp) Метод

BuildInstructionsFromObjectMetadata() статический приватный Метод

Builds an instruction object from the object metadata.
static private BuildInstructionsFromObjectMetadata ( GetObjectResponse response, EncryptionMaterials materials ) : EncryptionInstructions
response Amazon.S3.Model.GetObjectResponse /// A non-null object response that contains encryption information in its metadata. ///
materials EncryptionMaterials /// The non-null encryption materials to be used to encrypt and decrypt Envelope key. ///
Результат EncryptionInstructions
        internal static EncryptionInstructions BuildInstructionsFromObjectMetadata(GetObjectResponse response, EncryptionMaterials materials)
        {
            MetadataCollection metadata = response.Metadata;

            string base64EncodedEncryptedEnvelopeKey = metadata[keyInMetadata];
            byte[] encryptedEvelopeKey = Convert.FromBase64String(base64EncodedEncryptedEnvelopeKey);
            byte[] decryptedEnvelopeKey = DecryptEnvelopeKey(encryptedEvelopeKey, materials);

            string base64EncodedIV = metadata[initVectorInMetadata];
            byte[] IV = Convert.FromBase64String(base64EncodedIV);

            return new EncryptionInstructions(EncryptionMaterials.EmptyMaterialsDescription, decryptedEnvelopeKey, encryptedEvelopeKey, IV);
        }

Usage Example

        /// <summary>
        /// Updates object where the object input stream contains the decrypted contents.
        /// </summary>
        /// <param name="objectResponse">
        /// The getObject response whose contents are to be decrypted.
        /// </param>
        private void DecryptObjectUsingMetadata(GetObjectResponse objectResponse)
        {
            // Create an instruction object from the object metadata
            EncryptionInstructions instructions = EncryptionUtils.BuildInstructionsFromObjectMetadata(objectResponse, this.encryptionMaterials);

            // Decrypt the object with the instruction
            EncryptionUtils.DecryptObjectUsingInstructions(objectResponse, instructions);
        }