| | | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | | 2 | | // Licensed under the MIT License. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.IO; |
| | | 6 | | using System.Text; |
| | | 7 | | using System.Threading; |
| | | 8 | | using System.Threading.Tasks; |
| | | 9 | | using Azure.Storage.Cryptography; |
| | | 10 | | using Azure.Storage.Cryptography.Models; |
| | | 11 | | using Azure.Storage.Queues.Specialized.Models; |
| | | 12 | | |
| | | 13 | | namespace Azure.Storage.Queues |
| | | 14 | | { |
| | | 15 | | internal class QueueClientSideEncryptor |
| | | 16 | | { |
| | | 17 | | private readonly ClientSideEncryptor _encryptor; |
| | | 18 | | |
| | 0 | 19 | | public QueueClientSideEncryptor(ClientSideEncryptor encryptor) |
| | | 20 | | { |
| | 0 | 21 | | _encryptor = encryptor; |
| | 0 | 22 | | } |
| | | 23 | | |
| | | 24 | | public async Task<string> ClientSideEncryptInternal(string messageToUpload, bool async, CancellationToken cancel |
| | | 25 | | { |
| | 0 | 26 | | var bytesToEncrypt = Encoding.UTF8.GetBytes(messageToUpload); |
| | 0 | 27 | | (byte[] ciphertext, EncryptionData encryptionData) = await _encryptor.BufferedEncryptInternal( |
| | 0 | 28 | | new MemoryStream(bytesToEncrypt), |
| | 0 | 29 | | async, |
| | 0 | 30 | | cancellationToken).ConfigureAwait(false); |
| | | 31 | | |
| | 0 | 32 | | return EncryptedMessageSerializer.Serialize(new EncryptedMessage |
| | 0 | 33 | | { |
| | 0 | 34 | | EncryptedMessageText = Convert.ToBase64String(ciphertext), |
| | 0 | 35 | | EncryptionData = encryptionData |
| | 0 | 36 | | }); |
| | 0 | 37 | | } |
| | | 38 | | } |
| | | 39 | | } |