Otrzymuję ObjectDisposedException: Safe handle został zamknięty.ObjectDisposedException Podczas używania MD5 ComputeHash
To jest mój kod:
Próbuję utworzyć interfejs i wdrażania klasy, która pozwoli mi uzyskać ciąg, należy dołączyć do niego znanego klucza, obliczenia skrótu MD5 dla tego łańcucha i klucz, a zwrotu obliczoną hash:
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();
}
}
Dzięki
Która linia kodu zgłasza wyjątek? – ken2k
Czy 'hashed.ToHexString()' jest metodą rozszerzenia? Wkleiłem twój kod, a metoda nie istnieje ... – Laoujin
Witam, jest to metoda rozszerzenia. linia, która wyrzuca, to: var hashed = _hashAlgo.ComputeHash (Encoding.UTF8.GetBytes (strWithKey)); – user1625867