Generate Hmac token using secret key
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
14-01-22 06:17 PM
Hi. I need to create a hmac token using a secret key. I would really appreciate if someone could please provide the code. Many thanks!
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
14-01-22 08:48 PM
@Kim Dougan,
You're going to have to provide a bit more information. You say a "hmac token". Do you mean an "HMAC signature"? Is this something you need to apply to a web request? Do you know what type of HMAC? Are we talking HMAC-256, HMAC-MD5, etc.
You can find more details about the HMAC capability of .NET here. Ultimately, this is what would be used within a Code stage or Global Code page to generate your HMAC signature.
Cheers,
Eric
You're going to have to provide a bit more information. You say a "hmac token". Do you mean an "HMAC signature"? Is this something you need to apply to a web request? Do you know what type of HMAC? Are we talking HMAC-256, HMAC-MD5, etc.
You can find more details about the HMAC capability of .NET here. Ultimately, this is what would be used within a Code stage or Global Code page to generate your HMAC signature.
Cheers,
Eric
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
14-01-22 11:22 PM
@ewilson
Thank you for replying.
Yes - it is a HMAC signature using SHA 256. It will be used for an api call between my company and a third party.
many thanks
Kim
Thank you for replying.
Yes - it is a HMAC signature using SHA 256. It will be used for an api call between my company and a third party.
many thanks
Kim
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
15-01-22 12:11 AM
@Kim Dougan,
Without knowing the 3rd party platform and it's expectations for the content of the message, the best I can offer are some examples.
This is probably the most basic example of computing an HMAC256 hash for a signature:
You'll need to add a reference to the assembly mscorlib.dll and the namespace System.Security.Cryptography in your Code Options.
If you grab a copy of the Blue Prism AWS REST Utility VBO from the Digital Exchange, there's a more complex example of how to calculate an HMAC256 signature for requests to AWS services. This is an example where the platform (AWS in this case) has specific expectations regarding the various bits of data that should be included in the signature.
There are some additional examples on this Stack Overflow thread.
Cheers,
Eric
Without knowing the 3rd party platform and it's expectations for the content of the message, the best I can offer are some examples.
This is probably the most basic example of computing an HMAC256 hash for a signature:
private string GetHMAC(string text, string key)
{
key = key ?? "";
using (var hmacsha256 = new HMACSHA256(Encoding.UTF8.GetBytes(key)))
{
var hash = hmacsha256.ComputeHash(Encoding.UTF8.GetBytes(text));
return Convert.ToBase64String(hash);
}
}
You'll need to add a reference to the assembly mscorlib.dll and the namespace System.Security.Cryptography in your Code Options.
If you grab a copy of the Blue Prism AWS REST Utility VBO from the Digital Exchange, there's a more complex example of how to calculate an HMAC256 signature for requests to AWS services. This is an example where the platform (AWS in this case) has specific expectations regarding the various bits of data that should be included in the signature.
There are some additional examples on this Stack Overflow thread.
Cheers,
Eric
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-08-22 01:43 PM
Hi @ewilson,
I am trying also trying to create the HAMC-256 signature with the below requirement from the https://jwt.io :

Please not that the "secret base64 encoded" checkbox is checked.
Any idea/code like below in how I can achieve that?
I have the header, payload and encryption key details with me.
I am trying also trying to create the HAMC-256 signature with the below requirement from the https://jwt.io :
Please not that the "secret base64 encoded" checkbox is checked.
Any idea/code like below in how I can achieve that?
I have the header, payload and encryption key details with me.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-08-22 04:23 PM
Hi @Manish Rawat,
In my experience, if you're trying to create something similar to jwt.io then you're looking at create a JWT (Json Web Token). The best way to do that, is to use an existing library. The one I've used in the past is JWT.Net along with BouncyCastle.
Take a look at this thread and you should see some example code I posted towards the end of the thread.
Cheers,
Eric
In my experience, if you're trying to create something similar to jwt.io then you're looking at create a JWT (Json Web Token). The best way to do that, is to use an existing library. The one I've used in the past is JWT.Net along with BouncyCastle.
Take a look at this thread and you should see some example code I posted towards the end of the thread.
Cheers,
Eric
