Getting an error message “Error occurred while decoding OAEP padding” while trying to retrieve the entities from Azure Table Storage

送分小仙女□ 提交于 2019-12-11 01:47:30

问题


I am encrypting the table in the following way.

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;

    }

My Encrypted entity

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

While retrieving, I am using the following code

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

I am getting an error saying decryption error. The inner exception says "Error occurred while decoding OAEP padding."


回答1:


I also tried your code and official document code. If we query the table that just one entity in the query result, then we could get the decrypted info correctly. If more than one entities then it will get the same error "Error occurred while decoding OAEP padding." as your mentioned. It seems that SDK that not support to query more entities at one time currently. We can report our requirement to the Azure storage SDK project or give our feedback Azure team.

Update:

demo code:

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

        }
    }



回答2:


Update: It turns out this didn't work; I inadvertently changed something that had disabled the encryption.

I was getting the exception with both Execute and ExecuteQuerySegmented. For me, the solution turned out to be setting the activation date of the key (it was previously unset -- the checkbox wasn't checked).



来源:https://stackoverflow.com/questions/41862839/getting-an-error-message-error-occurred-while-decoding-oaep-padding-while-tryi

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