The method signature must be generated by taking the query string, and creating a HMAC-SHA256 signature using your API key as the secret key.

salesforce way of generating signature

String algorithmName = 'RSA';
String key = '';
Blob privateKey = EncodingUtil.base64Decode(key);
Blob input = Blob.valueOf('12345qwerty');
Crypto.sign(algorithmName, input, privateKey);

its not working. I am not able to get the meaning of first line, I have referred this links http://blog.jeffdouglas.com/2010/07/06/using-rsa-sha1-with-salesforce-crypto-class/ enter link description here

what should be proper value of input :: any random value OR some meaningful value

2 Answers 2


The input for String key should be the PKCS#8 formatted Private key. If you follow the instructions on the blog you linked to, use the string of characters between the outputted -----BEGIN PRIVATE KEY----- and -----END PRIVATE KEY-----.

Short Version of instructions -

  1. Generate a private / public key pair (CA or Self signed is up to you), formatted RSA / SHA1, in .PEM format.
  2. Convert .pem format private key to PKCS#8 format openssl pkcs8 -topk8 -nocrypt -in myPrivateKey.pem -outform PEM
  3. Take terminal output between -----BEGIN PRIVATE KEY----- and -----END PRIVATE KEY----- and use as String key = ''; - Make sure you do not have any line-breaks or carriage returns in the string, as is usually output to the terminal. This will make your key not work as Apex does not support multi-line strings.

I am a NodeJS developer and am confronted with the same confusing problem. Just as the comment above said, the PKCS8 salesforce wants is a little bit different from what can be generated by Node's native crypto module.

  .replace(/-{5}(BEGIN|END) PRIVATE KEY-{5}/g, '')
  .replace(/\n/g, ''),

After wasting a whole day, with the help of this blog I finally managed to figure out this trick in my LWC javascript.

In my JS case, I also had to output the signature-blob as base64 in apex due to not a valid utf-8 string error, which shows up if u use Blob.toString()

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .