Generating Base-64 SHA-1 Signature Header for Rackspace API in Apex

This post shares a small code snippet to generate a base-64 SHA1 Hash, which is typically used in passing as a signature header to some APIs. We tested this snippet with the Rackspace API Signature Header, which requires a base-64 SHA1 Hash.

The key point to note here is that we need to encode the binary hash, not the hex hash, into base-64, and thus the resulting string should be 28 characters long. Here is the gist snippet to generate the hash

This point is important to remember because developers sometimes pick the HEX conversion approach for base 64 encoding, as this is available in examples for SHA1 in Apex Developer Guide.

Hope this saves your time in case you require a base-74 SHA1 Hash in a similar format.

Abhinav Gupta

First Indian Salesforce MVP, rewarded Eight times in a row, has been blogging about Salesforce, Cloud, AI, & Web3 since 2011. Founded 1st Salesforce Dreamin event in India, called “Jaipur Dev Fest”. A seasoned speaker at Dreamforce, Dreamin events, & local meets. Author of many popular GitHub repos featured in official Salesforce blogs, newsletters, and books.

https://abhinav.fyi
Previous
Previous

Take aways from Salesforce Noida Developer Meetup !

Next
Next

Salesforce summer’12 Sorting enhancements reviewed !