Blue Prism Product

 View Only
last person joined: 18 hours ago 

This community covers the core Blue Prism product.

 Generate Hmac token using secret key

Kim Dougan's profile image
Kim Dougan posted 01-14-2022 18:19
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!
Eric Wilson's profile image
Eric Wilson
@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.

Kim Dougan's profile image
Kim Dougan
@Eric Wilson

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
Eric Wilson's profile image
Eric Wilson
@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:
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.