I could sit and mess around with this but I really don't know the finer points of how cryptography works in Java/Apex to risk sitting on a security hole.
Basically I'm creating a hash and then storing it, but I'm getting an error when I try and cast the blob object returned by the hash function to a string.
Here's my code:
String valueToHash = sfMessage.My_String__c + String.valueOf(sfMessage.My_Date__c); sfMessage.Hashed_String__c = Crypto.generateDigest('SHA-256', Blob.valueOf(valueToHash)).toString();
And the error I'm getting is a System.StringException telling me that in the second line "BLOB is not a valid UTF-8 string.
So how do I end up with a plain text representation (in whatever encoding Salesforce uses) of my hashed value? Also I've got the field length at 64 chars long, is this enough?