I have a hash algorithm object (SHA1 in this case) which I feed with data in order to finally get the hashed result upon calling the Result property.
The problem is that once m_HashAlgorithm.Hash property has been called, the object can no longer be used for feeding. If I try to feed it, I get: System.Security.Cryptography.CryptographicUnexpectedOperationException: Hash must be finalized before the hash value is retrieved.
I need to be able to get the an intermediate hash result but keep feeding and get another result later. Is there a way to achieve it?
private readonly HashAlgorithm m_HashAlgorithm;
public DigitalSignatureCreator(HashAlgorithm hashAlgorithm)
{
m_HashAlgorithm = hashAlgorithm;
m_MemoryStreamEncrypt = new MemoryStream();
m_CryptoStreamEncrypt = new CryptoStream(m_MemoryStreamEncrypt, m_HashAlgorithm, CryptoStreamMode.Write);
}
public void Feed(byte[] data, int offset, int count)
{
m_CryptoStreamEncrypt.Write(data, offset, count);
}
public byte[] Result
{
get
{
return m_HashAlgorithm.Hash;
}
}