【问题标题】:Encrypting image data before uploading to azure blob storage在上传到 Azure Blob 存储之前加密图像数据
【发布时间】:2014-02-15 14:49:49
【问题描述】:

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

我只是想弄清楚汤姆如何将我的加密方法集成到代码中。另外,我猜一旦它被加密而不是调用 blob.UploadFromFile() 我将调用 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();
    }

【问题讨论】:

    标签: c# .net asp.net-mvc azure azure-blob-storage


    【解决方案1】:

    在我看来,你可以通过 3 种方式做到这一点:

    1. 事先加密文件,然后上传该加密文件。
    2. 正如您所提到的,您可以读取字节数组中的文件,然后加密该字节数组并使用UploadFromByteArray 方法上传。
    3. 与 #2 类似,但您可以依赖流并使用 UploadFromStream 方法上传,而不是上传字节数组。

    【讨论】:

    • 谢谢,我知道如何使用方法 2。我会尽快用我的解决方案编辑我的帖子。
    • 您好@Ghandicap,请您提供从blob存储下载加密文件的建议。
    • @AnilD - 您找到问题的解决方案了吗?我正在寻找相同的
    • 高拉夫,你能帮忙吗?
    猜你喜欢
    • 2017-04-27
    • 2020-10-04
    • 2018-12-17
    • 1970-01-01
    • 2020-01-25
    • 2021-01-16
    • 2020-01-09
    • 2020-06-07
    • 2014-07-22
    相关资源
    最近更新 更多