我的代码在 .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/