gpt4 book ai didi

azure - 如何从 azure 数据表中以解密格式获取加密的机器人数据

转载 作者:行者123 更新时间:2023-12-03 00:29:21 25 4
gpt4 key购买 nike

我使用机器人应用程序(视觉C#)和机器人框架创建了QNA机器人。机器人状态数据存储在Azure数据表中。但对话数据(用户输入的数据)在 Azure 数据表中加密。我想解密它。我怎样才能解密它?

最佳答案

the data of the conversation(user typed data) is encrypted in Azure data table. I want to decrypt that. How can I decrypt that?

如果您想在存储后检索ConversationData,可以引用以下代码:

context.ConversationData.SetValue<string>("testval", "hello world");

string mes = "";

context.ConversationData.TryGetValue<string>("testval", out mes);

此外,对话历史记录以以下结构存储在 Azure 表存储中,如果您想检索对话历史记录并从 Activity0 中提取数据,可以尝试以下代码:

using Microsoft.Bot.Connector;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RetrieveHistory
{
class Program
{
static void Main(string[] args)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName={your_account_name};AccountKey={your_account_key};EndpointSuffix=core.windows.net");

CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

CloudTable table = tableClient.GetTableReference("{your_botconversationhistory_table_name}");

TableQuery<MessageEntity> query = new TableQuery<MessageEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "emulator|61b59bkmceee"));

foreach (MessageEntity entity in table.ExecuteQuery(query))
{
string myactivity = "";
using (var msi = new MemoryStream(entity.Activity0))
using (var mso = new MemoryStream())
{
using (var gs = new GZipStream(msi, CompressionMode.Decompress))
{
gs.CopyTo(mso);
}
myactivity = Encoding.UTF8.GetString(mso.ToArray());
}

Activity activity = JsonConvert.DeserializeObject<Activity>(myactivity);

Console.WriteLine("{0}, {1}\t{2}\t{3}\t{4}", entity.PartitionKey, entity.RowKey,
entity.From, entity.Recipient, activity.Text);
}



Console.ReadLine();
}



public class MessageEntity : TableEntity
{
public MessageEntity(string pk, string rk)
{
this.PartitionKey = pk;
this.RowKey = rk;
}

public MessageEntity() { }

public string From { get; set; }

public string Recipient { get; set; }

public byte[] Activity0 { get; set; }
}
}
}

属性和类型:

enter image description here

示例实体:

enter image description here

注意:您可以创建一个控制台应用程序并安装以下软件包,并使用我提供的代码进行测试以检索历史记录。

packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net46" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net46" />
<package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Bot.Connector" version="3.13.1" targetFramework="net46" />
<package id="Microsoft.IdentityModel.Logging" version="1.1.4" targetFramework="net46" />
<package id="Microsoft.IdentityModel.Protocols" version="2.1.4" targetFramework="net46" />
<package id="Microsoft.IdentityModel.Protocols.OpenIdConnect" version="2.1.4" targetFramework="net46" />
<package id="Microsoft.IdentityModel.Tokens" version="5.1.4" targetFramework="net46" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.2" targetFramework="net46" />
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net45" />
<package id="System.IdentityModel.Tokens.Jwt" version="5.1.4" targetFramework="net46" />
<package id="WindowsAzure.Storage" version="9.1.0" targetFramework="net45" />
</packages>

关于azure - 如何从 azure 数据表中以解密格式获取加密的机器人数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49483278/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com