Skip to content

Instantly share code, notes, and snippets.

@abhinavguptas
Created July 14, 2012 13:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save abhinavguptas/3111358 to your computer and use it in GitHub Desktop.
Save abhinavguptas/3111358 to your computer and use it in GitHub Desktop.
Apex(Salesforce): Generating base-64 SHA1 Hash for Rackspace API Signature Headers
//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