c# - 'System.Security.Cryptography.Rfc2898DeriveBytes' : type used in a using statement must be implicitly convertible to System. IDisposable

标签 c# .net using

我的代码在 .Net Framework 4.5 中工作,但是当我尝试在 .Net Framework 2.0 中编写相同的代码时,出现编译错误

'System.Security.Cryptography.Rfc2898DeriveBytes': type used in a using statement must be implicitly convertible to System.IDisposable

如何解决?

代码

[ComVisible(true)]
    public string HashPassword(string password)
    {

        byte[] salt;
        byte[] subkey;
        using (var deriveBytes = new Rfc2898DeriveBytes(password, SaltSize, PBKDF2IterCount))
        {
            salt = deriveBytes.Salt;
            subkey = deriveBytes.GetBytes(PBKDF2SubkeyLength);
        }

        var outputBytes = new byte[1 + SaltSize + PBKDF2SubkeyLength];
        //some more code goes here
        return Convert.ToBase64String(outputBytes);
    }

最佳答案

André's 中汲取灵感评论,看起来 Dispose 方法直到 .NET 4 才被引入:DeriveBytes.Dispose (注:“其他版本”)

您可以看一下Dispose 方法在当前框架中是如何实现的,并考虑将其应用到您的项目中:Source Browser

关于c# - 'System.Security.Cryptography.Rfc2898DeriveBytes' : type used in a using statement must be implicitly convertible to System. IDisposable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48291440/

相关文章:

c# - 发布我的 C# 项目时数据库不工作

c# - Linq 查询问题

.net - 将行颜色绑定(bind)到 MVVM 中的属性(取决于行中的数据)

c# - 如何在 .Net 中获得最大允许文件大小?

c++ - 从 C++ 中的函数 typedef 制作函数指针 typedef?

c# - RDLC 报告中的渲染 PDF 中不显示 Base64 图像

c# - 如何将现有联系人添加到现有组

c# - 公共(public)静态变量 c# 使用正确吗?

php - 使用变量作为命名空间

c# - 我想知道在迭代数据读取器对象时连接状态和 'yield' 对代码性能的影响