sha256¶
The sha256 filter calculates and returns the SHA-256 hash of a string. SHA-256 is a cryptographic hash function that generates a unique, fixed-size (256-bit or 32-byte) hash value from an input string. This hash is often used for verifying data integrity, password storage, or digital signatures.
Functionality
- Strings: Takes a string as input.
- Hashing: Computes the SHA-256 hash of the input string.
- Output: Returns a new string representing the hexadecimal representation of the hash value.
Syntax
ArgumentsThe sha256 filter does not require any arguments.
Code Samples
Example 1: Hashing a Password
Output: (The actual output will be a long hexadecimal string like the following)
Example 2: Verifying Data Integrity {% assign original_data = "This is some important data." %}
{% assign received_data = "This is some important data." %}
{% assign original_hash = original_data | sha256 %}
{% assign received_hash = received_data | sha256 %}
{% if original_hash == received_hash %}
Data integrity verified
{% else %}
Data has been modified
{% endif %}
Outliers and Special Cases¶
- Empty Strings: If the input string is empty, the
sha256filter still returns a hash value (the hash of an empty string). - Non-String Input: If the input is not a string, the filter might attempt to convert it to a string or return an error, depending on how Experience Builder handles type conversions.
Key Points¶
- The
sha256filter is a powerful tool for security and data integrity applications. - SHA-256 hashes are designed to be one-way functions, making it extremely difficult (practically impossible) to reverse the process and obtain the original string from the hash.
- This filter is commonly used for:
- Securely storing passwords (never store plain-text passwords).
- Verifying the integrity of data transmitted over networks.
- Generating unique identifiers for data.
- The output is a hexadecimal representation of the hash value, so it will always be a string of 64 characters.