Skip to content

Calculate hash values

This article explains how to hash text and file data and calculate the hash value.

Hashing is a technique that passes the original data through a hash function to generate a fixed-length string (a hash value).

Hashing the same data always produces the same hash value, and in practice, different data never produces the same hash value.

Because you can check whether two pieces of data are identical just by comparing their hash values, without comparing the data itself, hashing is used for purposes such as verifying that data hasn’t been tampered with.

Also, in practice, you can’t work out the original data from a hash value.

The action used here is called “Hash text.”

The action has the following parameters.

Parameter Value
Hash algorithm The algorithm to use for hashing (SHA256 / SHA384 / SHA512)
Encoding The encoding (character encoding) of the text to hash
Text to hash The text to hash

action

The hashing result is stored in the variable HashedText. The same text produces a different hash value if the encoding is different, so use the same encoding when you compare hash values (the default is “Unicode”).

Add the sample flow by copying and pasting

Section titled “Add the sample flow by copying and pasting”

As a sample, I prepared a flow that calculates a hash value from the specified text data.

Copy the following code and paste it into the Power Automate Desktop flow designer to add the actions.

SET HugeData TO $'''%'Data too large to transfer easily'%'''
Cryptography.HashText HashAlgorithm: Cryptography.HashAlgorithm.SHA256 Encoding: Cryptography.EncryptionEncoding.UTF8 TextToHash: HugeData HashedText=> HashedText
  1. In “Search actions,” type “Hash text.”

  2. Set the parameters as follows. %HugeData% is the variable created on the first line of the sample flow (the “Set variable” action).

    Parameter Value
    Hash algorithm SHA256
    Encoding UTF-8
    Text to hash %HugeData%
  3. When you run the flow, the result of hashing the specified text data is stored in a variable.

An error may occur when hashing runs.

We recommend adding error handling with an “On block error” block.