java md5.computehash_c# – 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();
}
}
謝謝
總結
以上是生活随笔為你收集整理的java md5.computehash_c# – ObjectDisposedException使用MD5 ComputeHash时的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring boot 配置tomcat
- 下一篇: c# 写文件注意问题及用例展示