Search code examples
hashsalesforcesha256apex-code

Saving a hashed string in Salesforce?


Not a SFDC expert but need to integrate a web form hosted in SFDC. For other reasons, this page needs to capture an initial password and send off the salted/sha256'd version of the password to another system or a human. I don't want to save the cleartext obviously.

What's the lightest touch way to hash the password before saving? I could do this in the browser except that I don't want to rely on Javascript.


Solution

  • Apex has a Crypto class which has a generateDigest method you need, something like:

    Blob hash = Crypto.generateDigest('SHA-256', Blob.valueOf(passwordString));