ObjectDisposedException When Using MD5 ComputeHash

I get an ObjectDisposedException: the safe handle is closed.

This is my code:

I am trying to create an interface and implement a class that will allow me to get a string, attach a known key to it, calculate the MD5 hash for this string and key and return the calculated 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();
    }
}

thank

+5
source share
2 answers

. _hashAlgo . , , , , ; , -. HashAlgorithm .

+5

. :

  • ? , MDS.Create() GetSignature()
  • ( SignService, _hashAlgo)? .
+1

All Articles