2

我正在通过以下方式加密表格。

public TableRequestOptions EncryptTableStorage()
    {
        // Create the IKey used for encryption.
        var key = new RsaKey("mykey");

        var policy = new TableEncryptionPolicy(key, null);

        TableRequestOptions options = new TableRequestOptions()
        {
            EncryptionPolicy = policy
        };


        return options;

    }

我的加密实体

 [EncryptProperty]
 public string ConsumerId { get; set; }

检索时,我正在使用以下代码

var query = new TableQuery<CloudModelDetail>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, cloudModelDetail.PartitionKey));
foreach (var entity in azureStorageAccount.VerifyCloudTable.ExecuteQuery(query, azureStorageAccount.EncryptTableStorage()))
{
  Console.WriteLine("{0}, {1}\t{2}\t{3}", entity.PartitionKey, entity.RowKey,
                    entity.ConsumerId, entity.ScoreVariables);
}

我收到一条错误消息,说解密错误。内部异常显示“解码 OAEP 填充时发生错误”。

4

2 回答 2

0

我也试过你的代码和官方文档代码。如果我们在查询结果中查询只有一个实体的表,那么我们可以正确获取解密信息。如果有多个实体,则会收到相同的错误“解码 OAEP 填充时发生错误”。正如你提到的。似乎SDK目前不支持一次查询更多实体。我们可以向 Azure 存储 SDK项目报告我们的要求或向我们的Azure 团队提供反馈。

更新:

演示代码:

    static void Main(string[] args)
    {
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
       "Your storage connection string");

        RsaKey key = new RsaKey("mykey" /* key identifier */);

        // Create the encryption policy to be used for upload and download.
        TableEncryptionPolicy policy = new TableEncryptionPolicy(key, null);

        TableRequestOptions options = new TableRequestOptions
        {
            EncryptionPolicy = policy
        };


        CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

        // Create the CloudTable object that represents the "tomtest" table.
        CloudTable table = tableClient.GetTableReference("tomtest");

        table.CreateIfNotExists();

        var insertList = new List<CloudModelDetail>();

        var cloudModelDetailEntity = new CloudModelDetail { ConsumerId = "0001-"+Guid.NewGuid() };

        table.Execute(TableOperation.Insert(cloudModelDetailEntity), options);

        TableRequestOptions retrieveoptions = new TableRequestOptions
        {
            EncryptionPolicy = policy
        };

        var query =
            new TableQuery<CloudModelDetail>().Where(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, cloudModelDetailEntity.RowKey));

       var list = table.ExecuteQuery(query, retrieveoptions);
        foreach (CloudModelDetail entity in list)
        {
            Console.WriteLine($"PartionKey:{entity.PartitionKey},RowKey:{entity.RowKey},ConsumerId: {entity.ConsumerId}");
        }

        Console.ReadKey();
    }



    public class CloudModelDetail : TableEntity
    {
        [EncryptProperty]
        public string ConsumerId { get; set; }
        public CloudModelDetail()
        {
            PartitionKey = "Name";
            RowKey = Guid.NewGuid().ToString();

        }
    }
于 2017-01-26T09:59:21.407 回答
0

更新:事实证明这不起作用;我无意中更改了禁用加密的内容。

我遇到了 Execute 和 ExecuteQuerySegmented 的异常。对我来说,解决方案是设置密钥的激活日期(之前未设置 - 未选中复选框)。

密钥版本配置

于 2017-02-11T09:20:24.810 回答