【问题标题】:how to import the Cryptographic library in asp.net 5如何在 asp.net 5 中导入密码库
【发布时间】:2021-11-23 14:07:25
【问题描述】:

你好我有以下缺点,原来在我的代码中我有以下:

private void CreatePasswordCreate(string password, out byte[] passwordCreate, out byte[] passwordRepeat) {
        using (var hmac = new System.Security.Cryptography.HMACSHA512())
        { 
            passwordCreate = hmac.Key;
            passwordRepeat = hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes(password));
        }
    }

但是在写它的时候我得到了以下错误:

CS0234:命名空间“System.Invoices.System”中不存在类型或命名空间名称“Security”(您是否缺少程序集引用?)

在我看来,之前显示的内容出现在以下代码行中,特别是“安全”一词

using (var hmac = new System.Security.Crytography.HMACSHA512())

我也收到以下错误:

CS0234:命名空间“System.Invoices.System”中不存在类型或命名空间名称“Text”(您是否缺少程序集引用?)

我在以下代码行中收到此错误:

passwordRepeat = hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes(password));

我不知道如何导入这个库,因为我是这个库的新手,我想知道如何添加这个库或者“安全”和“文本”类应该有什么内容,以及它应该去哪里它是不是因为它没有自动出现而被创建的?

using System

【问题讨论】:

  • 你熟悉 nuget 吗?作为一个新手并不丢人。但我不会从与安全相关的开发开始。
  • 是的,但如果我现在不开始,什么时候开始?如果没有,我永远不会学习,我来这里寻求解决方案,而不是让他们让我回到开始,帮助不会教我一个坏习惯

标签: c# asp.net5


【解决方案1】:

我已经解决了以下错误 而不是有解决方案的代码是这个

private void CreatePasswordCreate(string password, out byte[] passwordCreate, out byte[] passwordRepeat)
    {
        using (var hmac = new Security.Cryptography.HMACSHA512())
        {
            passwordRepeat = hmac.Key;
            passwordCreate = hmac.ComputeHash(Encoding.UTF8.GetBytes(password));
        }
    }

然后按以下方式调用在分配变量之前创建的函数

CreatePasswordCreate(model.password,out byte[] passwordCreate, out byte[] passwordRepeat );

并导入using System.Text;

但是它也可以通过以下方式工作,在密码学中添加系统

private void CreatePasswordCreate(string password, out byte[] passwordCreate, out byte[] passwordRepeat)
    {
        using (var hmac = new System.Security.Cryptography.HMACSHA512())
        {
            passwordRepeat = hmac.Key;
            passwordCreate = hmac.ComputeHash(Encoding.UTF8.GetBytes(password));
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-26
    • 2015-03-06
    • 1970-01-01
    • 2014-10-01
    • 1970-01-01
    • 2011-07-06
    相关资源
    最近更新 更多