SHA256 and SHA512 functions return wrong hash

Learn how database encoding affects hash values in Adobe Campaign. Explore the solution for discrepancies in the SHA256 and SHA512 functions.

Description description

Environment

  • Campaign
  • Campaign Classic

Issue/Symptoms

It was reported that SHA256 and SHA512 functions return a wrong hash.

The link below shows that someone else has also raised the same issue:

https://experienceleaguecommunities.adobe.com/t5/adobe-campaign-classic-questions/sha256-and-sha512-function-returns-wrong-hash/td-p/351035

Resolution resolution

A user has shared a solution:

The problem occurred because Adobe converts string datatype to nvarchar instead of varchar in the case when the DB is using Unicode encoding. In this case, the database encoding default is used as Unicode to support the Thai language. Therefore, Adobe converted the string to nvarchar.

For the functions SHA256 and SHA512, it works as normal, but it will return different values of hash for varchar and nvarchar.

In this case, it was possible to change that field (containing a mobile number only) to varchar and hash it correctly.

Adobe Community article:
https://experienceleaguecommunities.adobe.com/t5/adobe-campaign-classic-questions/sha256-and-sha512-functions-returning-wrong-hash/qaq-p/351034

Additionally, if the SQL Server is used, the digest function uses the UTF-16 representation of the string. You will not get the expected digest (which is often calculated on ASCII or UTF-8 character).

Example: hello will give 14cde7c9ad35de5a37fce2ac276742175028fd9f7cdf0dae01ff508b126429d9 as SHA-256 on the ASCII/UTF-8 representation of the string and will give 18fe2820b38427a08a5b49fb4d71a7027799bfe0050d3050ca4d3491a85aa0eb on the UTF-16 representation.

recommendation-more-help
3d58f420-19b5-47a0-a122-5c9dab55ec7f