function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Frank van Meegen 42Frank van Meegen 42 

Encrypt String to SHA256 without key

For a signature in an API connection I need to encode a string to SHA256 without using a key. Which method in APEX can I use for this?

String S = 'THIS IS AN EXAMPLE STRING';

If I encrupt this string to SHA256 via the following website I get a correct 64 character string without the use of a key:
http://md5decrypt.net/en/Sha256/#answer

Result = '2b970a5104771ac1890d755254e5ce9d2cc8e8d488961f241879e337fb8be502'

I cannot find a method in APEX that does the same.

The one that comes close is crypto.generateMac(algorithmName, input, privateKey) but this requires a key and Crypto.generateDigest(algorithmName, input) does not give a result that can be handled properly.
Frank van Meegen 42Frank van Meegen 42

Proper link to the SHA256 encrypt website:

http://md5decrypt.net/en/Sha256/#answer