Discuss this help topic in SecureBlackbox Forum

Calculate hash over data

To calculate hash over some data (often called a 'message digest'), use the TElHashFunction component:

  1. Create a TElHashFunction object, passing the algorithm you want to use for digesting: TElHashFunction hf = new TElHashFunction(SBConstants.Unit.SB_ALGORITHM_DGST_SHA256);
  2. Pass as much data as you need to the Update() method: byte[] text1 = Encoding.UTF8.GetBytes("The lazy dog jumps over the quick brown fox");
    hf.Update(text1, 0, text1.Length);

    byte[] text2 = Encoding.UTF8.GetBytes(" ...leaving the fox puzzled");
    hf.Update(text2, 0, text2.Length);
  3. Finalize the hashing and get the message digest with the Finish() method: byte[] digest = hf.Finish(); That's it, the digest contains the desired value.
For simpler cases, there is also a static TElHashFunction.Hash() method: byte[] digest = TElHashFunction.Hash(SBConstants.Unit.SB_ALGORITHM_DGST_SHA256, Encoding.UTF8.GetBytes("Anyone seen the fox around at all?!"));

How To articles related to low-level cryptography

Discuss this help topic in SecureBlackbox Forum