在上传到Azure Blob存储之前对图像数据进行加密

问题描述:

我有以下代码将映像上传到Azure blob存储.我想在上传到Blob之前对图像数据进行加密.我已经有一个用于加密和解密的帮助程序类,可以通过调用AESEncryption.Encrypt("plainText","key",salt);

I have the following code that uploads an image to Azure blob storage. I would like to encrypt the image data before uploading to the blob. I already have a helper class for encrypting and decrypting that I can use by calling AESEncryption.Encrypt("plainText", "key", salt");

我只是想弄清楚如何将我的加密方法集成到代码中.另外,我猜想一旦将其加密而不是调用blob.UploadFromFile(),我将调用blob.UploadFromByteArray().

I'm just trying to figure out how tom integrate my encryption method into the code. Also, I'm guessing that once it's encrypted instead of calling blob.UploadFromFile() I will be calling blob.UploadFromByteArray().

public override Task ExecutePostProcessingAsync()
    {
        try
        {
            // Upload the files to azure blob storage and remove them from local disk
            foreach (var fileData in this.FileData)
            {
                var filename = BuildFilename(Path.GetExtension(fileData.Headers.ContentDisposition.FileName.Trim('"')));

                // Retrieve reference to a blob
                var blob = _container.GetBlockBlobReference(filename);
                blob.Properties.ContentType = fileData.Headers.ContentType.MediaType;
                blob.UploadFromFile(fileData.LocalFileName, FileMode.Open);
                File.Delete(fileData.LocalFileName);
                Files.Add(new FileDetails
                {
                    ContentType = blob.Properties.ContentType,
                    Name = blob.Name,
                    Size = blob.Properties.Length,
                    Location = blob.Uri.AbsoluteUri
                });
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }

        return base.ExecutePostProcessingAsync();
    }

如我所见,您可以通过3种方式做到这一点:

As I see it, you could do it 3 ways:

  1. 事先加密文件,然后上传该加密文件.
  2. 如前所述,您可以读取字节数组中的文件,然后对该字节数组进行加密并使用 UploadFromByteArray 方法上传.
  3. 类似于#2,但是除了上传字节数组外,您还可以依靠流并使用 查看更多