小编use*_*867的帖子

ObjectDisposedException使用MD5 ComputeHash时

我收到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();
    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢

c# hash md5 cryptography cryptographic-hash-function

7
推荐指数
2
解决办法
1571
查看次数