Campaign Classic - SHA256 and SHA512 function returns wrong hash 2nd update

Description

The customer reported that SHA256 and SHA512 function returns a wrong hash.

They have found some users also have this issue here.
https://experienceleaguecommunities.adobe.com/t5/adobe-campaign-classic-questions/sha256-and-sha512-function-returns-wrong-hash/qaq-p/351035/comment-id/3882

Resolution

The customer shared a solution that they found:

The problem occurred because Adobe converts string datatype to nvarchar instead of varchar in the case when the DB is using unicode encoding.
In the customer’s case, database encoding default is used as unicode to support the Thai language. That’s why Adobe converted string to nvarchar.

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

In the customer’s 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 ut-8 character).

Example: “hello” will give 14cde7c9ad35de5a37fce2ac276742175028fd9f7cdf0dae01ff508b126429d9 as sha2-256 on the ascii/utf-8 representation of the string and will give 18fe2820b38427a08a5b49fb4d71a7027799bfe0050d3050ca4d3491a85aa0eb on the utf-16 representation.

On this page