CryptographicHash CryptographicHash CryptographicHash CryptographicHash CryptographicHash Class


Represents a reusable hashing object and contains the result of a hashing operation.

public : sealed class CryptographicHash : IHashComputation
struct winrt::Windows::Security::Cryptography::Core::CryptographicHash : IHashComputation
public sealed class CryptographicHash : IHashComputation
Public NotInheritable Class CryptographicHash Implements IHashComputation
// This class does not provide a public constructor.
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)


public void SampleReusableHash()
    // Create a string that contains the name of the hashing algorithm to use.
    String strAlgName = HashAlgorithmNames.Sha512;

    // Create a HashAlgorithmProvider object.
    HashAlgorithmProvider objAlgProv = HashAlgorithmProvider.OpenAlgorithm(strAlgName);

    // Create a CryptographicHash object. This object can be reused to continually
    // hash new messages.
    CryptographicHash objHash = objAlgProv.CreateHash();

    // Hash message 1.
    String strMsg1 = "This is message 1.";
    IBuffer buffMsg1 = CryptographicBuffer.ConvertStringToBinary(strMsg1, BinaryStringEncoding.Utf16BE);
    IBuffer buffHash1 = objHash.GetValueAndReset();

    // Hash message 2.
    String strMsg2 = "This is message 2.";
    IBuffer buffMsg2 = CryptographicBuffer.ConvertStringToBinary(strMsg2, BinaryStringEncoding.Utf16BE);
    IBuffer buffHash2 = objHash.GetValueAndReset();

    // Hash message 3.
    String strMsg3 = "This is message 3.";
    IBuffer buffMsg3 = CryptographicBuffer.ConvertStringToBinary(strMsg3, BinaryStringEncoding.Utf16BE);
    IBuffer buffHash3 = objHash.GetValueAndReset();

    // Convert the hashes to string values (for display);
    String strHash1 = CryptographicBuffer.EncodeToBase64String(buffHash1);
    String strHash2 = CryptographicBuffer.EncodeToBase64String(buffHash2);
    String strHash3 = CryptographicBuffer.EncodeToBase64String(buffHash3);


Call the HashAlgorithmProvider.CreateHash or MacAlgorithmProvider.CreateHash method to create a CryptographicHash object. You can open a hash algorithm provider, by name, for any of the following algorithm names:

  • MD5
  • SHA1
  • SHA256
  • SHA384
  • SHA512


Append(IBuffer) Append(IBuffer) Append(IBuffer) Append(IBuffer) Append(IBuffer)

Appends a binary encoded string to the data stored in the CryptographicHash object.

public : void Append(IBuffer data)
void Append(IBuffer data) const;
public void Append(IBuffer data)
Public Function Append(data As IBuffer) As void
IBuffer IBuffer IBuffer

Data to append.


Call the GetValueAndReset method to retrieve data from the CryptographicHash object and empty the buffer.

GetValueAndReset() GetValueAndReset() GetValueAndReset() GetValueAndReset() GetValueAndReset()

Gets hashed data from the CryptographicHash object and resets the object.

public : IBuffer GetValueAndReset()
IBuffer GetValueAndReset() const;
public IBuffer GetValueAndReset()
Public Function GetValueAndReset() As IBuffer
var iBuffer = cryptographicHash.getValueAndReset();

Hashed data.


Call the Append method to add data to the CryptographicHash object.