-
-
Save webon100/9de4efaa0f0734f20cc1d40ef10bdcc7 to your computer and use it in GitHub Desktop.
Apex(Salesforce): Generating base-64 SHA1 Hash for Rackspace API Signature Headers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Example String to be passed for SHA1 hash generation | |
String targetString = 'eGbq9/2hcZsRlr1JV1PiRackspace Management Interface20010308143725QHOvchm/40czXhJ1OxfxK7jDHr3t'; | |
// Convert to BLOB | |
Blob targetBlob = Blob.valueOf(targetString); | |
// Generate SHA1 digest | |
Blob hashSHA1 = Crypto.generateDigest('SHA1', targetBlob); | |
// For Rackspace Compatiblity encode the binary into BASE 64 | |
// this will result in 28 chars long string | |
String hashBase64SHA1 = EncodingUtil.base64encode (hashSHA1); | |
// should print : "46VIwd66mOFGG8IkbgnLlXnfnkU=" | |
System.debug (hashBase64SHA1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment