我收到 ObjectDisposedException:安全句柄已关闭。
这是我的代码:
我正在尝试创建一个接口和实现类,它将使我能够获取一个字符串,将一个已知密钥附加到它,为该字符串和密钥计算 MD5 哈希,并返回计算出的哈希:
public interface ISignService
{
string GetSignature(string str);
}
public class SignService : ISignService
{
private readonly ISignSettings _signSettings;
private readonly HashAlgorithm _hashAlgo;
public SignService(ISignSettings signSettings)
{
_signSettings = signSettings;
_hashAlgo = MD5.Create();
}
public string GetSignature(string str)
{
var strWithKey = str + _signSettings.EncryptionKey;
var hashed = _hashAlgo.ComputeHash(Encoding.UTF8.GetBytes(strWithKey));
return hashed.ToHexString();
}
}
谢谢