为什么会出现此错误名称“EncryptStringToBytes_Aes”当前上下文中不存在

发布于 2025-01-13 19:04:46 字数 823 浏览 2 评论 0原文

当尝试使用 Aes 将字符串加密为字节时,我收到此错误消息

当前上下文中不存在名称“EncryptStringToBytes_Aes”

这是我的代码

namespace Encryption learning
{
    class Program
    {
        static void Main(string[] args)
        {

            string encryption64xx = "BASE64";

            byte[] key = new byte[] { 0x00, 0x00, 0x60, 0x1F, 0xA1, 0xFF, 0x00, 0x25, 0x60, 0x1F, 0xA1, 0xFF, 0x00, 0x21, 0x21, 0x1F };
            byte[] iv = new byte[] { 0x00, 0xBC, 0xF0, 0xA3, 0xA1, 0xBC, 0x12, 0x2A, 0xF0, 0xA3, 0xA1, 0xBC, 0x13, 0xA2, 0xF0, 0xA3 };


            byte[] encrypted64x = EncryptStringTobytes_Aes(encryption64xx, key, iv);

            string encrypted64 = Convert.ToBase64String(encrypted64x);

            System.IO.File.WriteAllText(@"teste.txt", encrypted64);





        }
    }
}

When trying to encrypt string to bytes using Aes I'm getting this error message

The name 'EncryptStringToBytes_Aes' does not exist in the current context

Here's my code

namespace Encryption learning
{
    class Program
    {
        static void Main(string[] args)
        {

            string encryption64xx = "BASE64";

            byte[] key = new byte[] { 0x00, 0x00, 0x60, 0x1F, 0xA1, 0xFF, 0x00, 0x25, 0x60, 0x1F, 0xA1, 0xFF, 0x00, 0x21, 0x21, 0x1F };
            byte[] iv = new byte[] { 0x00, 0xBC, 0xF0, 0xA3, 0xA1, 0xBC, 0x12, 0x2A, 0xF0, 0xA3, 0xA1, 0xBC, 0x13, 0xA2, 0xF0, 0xA3 };


            byte[] encrypted64x = EncryptStringTobytes_Aes(encryption64xx, key, iv);

            string encrypted64 = Convert.ToBase64String(encrypted64x);

            System.IO.File.WriteAllText(@"teste.txt", encrypted64);





        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吲‖鸣 2025-01-20 19:04:46

EncryptStringTobytes_Aes() 是一个库方法,需要从外部库/包导出,以便可以在您的程序中使用。

根据 此 Microsoft 文档页面,它位于 Microsoft.Bot.Configuration.dll 文件中,您可以使用 NuGet 下载该文件。

要从解决方案资源管理器面板执行此操作,请右键单击项目名称并选择“管理 NuGet 包”。从左侧面板中查找并选择“浏览”选项卡,然后在“浏览”下的搜索栏中输入“Microsoft.Bot.Configuration”,然后按 Enter 键。下载您看到的与文件名匹配的第一个 NuGet 数据包。安装 NuGet 数据包后,转到 program.cs 文件并将

using Microsoft.Bot.Configuration.Encryption;

添加到文件顶部。

现在你应该可以使用这个方法了

EncryptStringTobytes_Aes() is a library method and it needs to be exported from an external library/package so that it can be used in your program.

According to this Microsoft docs page, It is located in the Microsoft.Bot.Configuration.dll file which you can download using NuGet.

To do that from the solution explorer panel, right-click on your project name and select "manage NuGet packages". Find and select the "Browse" tab from the panel on the left and to the search bar located under "Browse" type "Microsoft.Bot.Configuration" and hit enter. Download the first NuGet packet you see that matches the filename. After the NuGet packet is installed go to your program.cs file and add

using Microsoft.Bot.Configuration.Encryption;

to the top of your file.

Now you should be able to use this method

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文