我收到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();
}
}
谢谢