static private EncryptRequestUsingInstruction ( Stream toBeEncrypted, |
||
toBeEncrypted | Stream | /// The stream whose contents are to be encrypted. /// |
instructions | /// The instruction that will be used to encrypt the object data. /// | |
Résultat | Stream |
/// <summary> /// Updates the request where the input stream contains the encrypted object contents. /// </summary> /// <param name="request"></param> private void GenerateEncryptedUploadPartRequest(UploadPartRequest request) { string uploadID = request.UploadId; UploadPartEncryptionContext contextForEncryption = currentMultiPartUploadKeys[uploadID]; byte[] envelopeKey = contextForEncryption.EnvelopeKey; byte[] IV = contextForEncryption.NextIV; EncryptionInstructions instructions = new EncryptionInstructions(EncryptionMaterials.EmptyMaterialsDescription, envelopeKey, IV); if (request.IsLastPart == false) { if (contextForEncryption.IsFinalPart == true) { throw new AmazonClientException("Last part has already been processed, cannot upload this as the last part"); } if (request.PartNumber < contextForEncryption.PartNumber) { throw new AmazonClientException("Upload Parts must in correct sequence"); } request.InputStream = EncryptionUtils.EncryptUploadPartRequestUsingInstructions(request.InputStream, instructions); contextForEncryption.PartNumber = request.PartNumber; } else { request.InputStream = EncryptionUtils.EncryptRequestUsingInstruction(request.InputStream, instructions); contextForEncryption.IsFinalPart = true; } request.RequestState.Add(S3CryptoStream, request.InputStream); }
/// <summary> /// Updates the request where the metadata contains encryption information /// and the input stream contains the encrypted object contents. /// </summary> /// <param name="putObjectRequest"> /// The request whose contents are to be encrypted. /// </param> private void GenerateEncryptedObjectRequestUsingMetadata(PutObjectRequest putObjectRequest) { // Create instruction EncryptionInstructions instructions = EncryptionUtils.GenerateInstructions(this.encryptionMaterials); EncryptionUtils.AddUnencryptedContentLengthToMetadata(putObjectRequest); // Encrypt the object data with the instruction putObjectRequest.InputStream = EncryptionUtils.EncryptRequestUsingInstruction(putObjectRequest.InputStream, instructions); // Update the metadata EncryptionUtils.UpdateMetadataWithEncryptionInstructions(putObjectRequest, instructions); }
/// <summary> /// Updates the request where the instruction file contains encryption information /// and the input stream contains the encrypted object contents. /// </summary> /// <param name="putObjectRequest"></param> private void GenerateEncryptedObjectRequestUsingInstructionFile(PutObjectRequest putObjectRequest) { // Create instruction EncryptionInstructions instructions = EncryptionUtils.GenerateInstructions(this.encryptionMaterials); EncryptionUtils.AddUnencryptedContentLengthToMetadata(putObjectRequest); // Encrypt the object data with the instruction putObjectRequest.InputStream = EncryptionUtils.EncryptRequestUsingInstruction(putObjectRequest.InputStream, instructions); // Create request for uploading instruction file PutObjectRequest instructionFileRequest = EncryptionUtils.CreateInstructionFileRequest(putObjectRequest, instructions); S3ClientForInstructionFile.PutObject(instructionFileRequest); }