Encrypting image data before uploading to azure blob storage

放肆的年华 提交于 2021-02-11 17:45:30

问题


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");

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();
    }

回答1:


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

  1. Encrypt the file beforehand and then upload that encrypted file.
  2. As you mentioned, you could read the file in byte array and then encrypt that byte array and upload it using UploadFromByteArray method.
  3. Similar to #2 but instead of uploading byte array, you could rely on streams and upload using UploadFromStream method.


来源:https://stackoverflow.com/questions/21335565/encrypting-image-data-before-uploading-to-azure-blob-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!