<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: HMAC SHA-512 hash not matching in webhook callback in Integration and Testing</title>
    <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/HMAC-SHA-512-hash-not-matching-in-webhook-callback/m-p/82772#M52159</link>
    <description>&lt;P&gt;private static string ByteToString(byte[] buff)&lt;BR /&gt;{&lt;BR /&gt;string sbinary = "";&lt;BR /&gt;for(var i=0; i&amp;lt;=buff.Length-1; i++)&lt;BR /&gt;{&lt;BR /&gt;sbinary += buff[i].ToString("X2");&lt;BR /&gt;}&lt;BR /&gt;return sbinary;&lt;BR /&gt;}&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ended having to use this instead of Convert.ToBase64String(payloadHashbytes).&lt;/P&gt;&lt;P&gt;byte[] keybytes = Encoding.UTF8.GetBytes(secret);&lt;/P&gt;&lt;P&gt;System.Security.Cryptography.HMACSHA512 hmac1 = new System.Security.Cryptography.HMACSHA512(keybytes);&lt;BR /&gt;byte[] payloadbytes = Encoding.UTF8.GetBytes(payload);&lt;BR /&gt;byte[] payloadhashbytes = hmac1.ComputeHash(payloadbytes);&lt;BR /&gt;//string hmacString = Convert.ToBase64String(payloadhashbytes); //this is not working...had to use below ByteToString method&lt;BR /&gt;string hmacString = ByteToString(payloadhashbytes);&lt;BR /&gt;return hmacString;&lt;/P&gt;</description>
    <pubDate>Thu, 19 May 2022 16:11:04 GMT</pubDate>
    <dc:creator>Harini</dc:creator>
    <dc:date>2022-05-19T16:11:04Z</dc:date>
    <item>
      <title>HMAC SHA-512 hash not matching in webhook callback</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/HMAC-SHA-512-hash-not-matching-in-webhook-callback/m-p/57162#M31894</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I recently began working on integrating with the new Webhook API to subscribe to events.&amp;nbsp; This is being integrated into an existing ASP.NET solution written in C#.&amp;nbsp; I would like to validate webhook messages using the X-ANET-Signature header, but so far have not been able to produce a matching signature in my test setup.&amp;nbsp; My code is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; protected void Page_Load(object sender, EventArgs e)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string keytext = "MY AUTHORIZE.NET SIGNATURE KEY";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; byte[] key = HexDecode(keytext);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HMACSHA512 hmacsha = new HMACSHA512(key);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; byte[] hash = hmacsha.ComputeHash(Request.InputStream);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string computedHash = HashEncode(hash);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//compare with the X-ANET-Signature, they don't match&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private static byte[] HexDecode(string hex)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var bytes = new byte[hex.Length / 2];&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = 0; i &amp;lt; bytes.Length; i++)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bytes[i] = byte.Parse(hex.Substring(i * 2, 2), NumberStyles.HexNumber);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return bytes;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private static string HashEncode(byte[] hash)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return BitConverter.ToString(hash).Replace("-", "").ToLower();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any guidance would be much appreciated!&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 15:54:34 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/HMAC-SHA-512-hash-not-matching-in-webhook-callback/m-p/57162#M31894</guid>
      <dc:creator>bschuller</dc:creator>
      <dc:date>2017-03-06T15:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: HMAC SHA-512 hash not matching in webhook callback</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/HMAC-SHA-512-hash-not-matching-in-webhook-callback/m-p/57201#M31931</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.developer.cybersource.com/t5/user/viewprofilepage/user-id/21339"&gt;@bschuller&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't tell exactly from your code where the problem might be, but here's some things to check.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is Request.InputStream getting the body, the whole body, and nothing but the body? Add a line to output that and see if it's the entire JSON object, or something less/more.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Take whatever you've output from&amp;nbsp;&lt;SPAN&gt;Request.InputStream and calculate the&amp;nbsp;HMAC for&amp;nbsp;it outside your code. Using a website like&amp;nbsp;&lt;A href="http://www.freeformatter.com/hmac-generator.html" target="_blank"&gt;http://www.freeformatter.com/hmac-generator.html&lt;/A&gt;, you can put in the body that you've retrieved, and put in your signature key as the key. If you get a matching HMAC from that site, then you know your code is either mangling the signature key in the HexDecode function, or mangling the message body, or doing something else bad. If you&amp;nbsp;&lt;EM&gt;don't&lt;/EM&gt; get a matching HMAC from the web site, then maybe what you retrieved as the message body isn't complete or has something extra. Or, you're just using the wrong signature key.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Basically, it's just a strategy of breaking down what you're doing into steps, and checking the output at each point against a known working implementation.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here's an example transaction I just tried. The X-Anet-Signature: header is:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;sha512=9607C69D2734514554CE13D923D19939563F2FD6567D239F49F0DF0D08865632A0FB98061B4620CC52C47BB8BF6E2B69A15A67E4C98E81D7D65111076C515C6A&lt;/PRE&gt;&lt;P&gt;The body of the notification is:&lt;/P&gt;&lt;PRE&gt;{"notificationId":"f813b98f-3552-4eeb-ba40-acb4704eeba3","eventType":"net.authorize.payment.authcapture.created","eventDate":"2017-03-08T17:35:37.155999Z","webhookId":"63d6fea2-aa13-4b1d-a204-f5fbc15942b7","payload":{"responseCode":1,"authCode":"8VTPDC","avsResponse":"Y","authAmount":10.00,"entityName":"transaction","id":"60019392075"}}&lt;/PRE&gt;&lt;P&gt;My signature key is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;2679A5D5785C9B26CF921E1754765CDDB265C9C88400786923E5343B315954FAFB4B7BF608818F6A21766741E8637DC206F286C725908C777ED4127D8562163D&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using those values, I'm able to generate a HMAC that matches the one returned in the header.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let us know how it works out.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 18:20:00 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/HMAC-SHA-512-hash-not-matching-in-webhook-callback/m-p/57201#M31931</guid>
      <dc:creator>Aaron</dc:creator>
      <dc:date>2017-03-08T18:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: HMAC SHA-512 hash not matching in webhook callback</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/HMAC-SHA-512-hash-not-matching-in-webhook-callback/m-p/57221#M31950</link>
      <description>&lt;P&gt;Hi Aaron,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the reply.&amp;nbsp; I did get things sorted, so I thought I'd go ahead and post the details of the problem in case it helps anyone else.&amp;nbsp; I had already followed the various debugging steps you mentioned, but it helped to go over to the hmac-generator page you sent, since it showed me the problem had to be in my conversion of the signature key into a byte array.&amp;nbsp; I had mistakenly thought the signature key was to be read as pairs of characters making up a single hex digit, so I was parsing it like "26", "79", "A5"...etc (using your signature key as an example).&amp;nbsp; So I was getting a byte array of length 64 instead of 128.&amp;nbsp; Needed to just take the text of the key, do a simple "Encoding.ASCII.GetBytes(keytext)" instead, and it worked from that point forward.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate the help!&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2017 20:51:08 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/HMAC-SHA-512-hash-not-matching-in-webhook-callback/m-p/57221#M31950</guid>
      <dc:creator>bschuller</dc:creator>
      <dc:date>2017-03-09T20:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: HMAC SHA-512 hash not matching in webhook callback</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/HMAC-SHA-512-hash-not-matching-in-webhook-callback/m-p/61178#M35668</link>
      <description>&lt;P&gt;This post has been helpful, but I'm still stuck. I've spent far too long trying to figure this same thing out and I'm really close, thanks to your help. I'm just having a hard time with the final syntax. I'm working in VB and I'm confusing things I think with the conversion from C#.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please post your final code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- Jason&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 23:18:39 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/HMAC-SHA-512-hash-not-matching-in-webhook-callback/m-p/61178#M35668</guid>
      <dc:creator>Janga</dc:creator>
      <dc:date>2018-01-10T23:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: HMAC SHA-512 hash not matching in webhook callback</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/HMAC-SHA-512-hash-not-matching-in-webhook-callback/m-p/61180#M35670</link>
      <description>&lt;P&gt;We do have a github project done by a developer for&amp;nbsp;supporting&amp;nbsp; webhooks&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/dns12345/AuthNet.WebHooks" target="_blank"&gt;https://github.com/dns12345/AuthNet.WebHooks&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it helps !!&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 06:26:26 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/HMAC-SHA-512-hash-not-matching-in-webhook-callback/m-p/61180#M35670</guid>
      <dc:creator>Anurag</dc:creator>
      <dc:date>2018-01-11T06:26:26Z</dc:date>
    </item>
    <item>
      <title>Re: HMAC SHA-512 hash not matching in webhook callback</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/HMAC-SHA-512-hash-not-matching-in-webhook-callback/m-p/61197#M35687</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@anuragg29 wrote:&lt;BR /&gt;&lt;P&gt;We do have a github project done by a developer for&amp;nbsp;supporting&amp;nbsp; webhooks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/dns12345/AuthNet.WebHooks" target="_blank"&gt;https://github.com/dns12345/AuthNet.WebHooks&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope it helps !!&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;BR /&gt;Thanks for your help... I checked out the source code on github, which is great if you speak C#.&amp;nbsp; =) It did give me some ideas of how to implement things.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For struggling VB peeps trying to make sense of it all, I finally&amp;nbsp;came up with some code after days of wrapping my head around it all. There may be a better/easier way to do this, however what I've got here seems to work. I hope this helps someone. Feel free to make it better.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are the steps:&lt;/P&gt;&lt;P&gt;1) From your Authorize.net account, create your Signature Key. (Account Settings &amp;gt; API Credentials &amp;amp; Keys). Save this somewhere... you're going to need it.&lt;/P&gt;&lt;P&gt;2) Create your webhook endpoint URL. (Business Settings &amp;gt; Webhooks). Make sure you keep it INACTIVE. When it's INACTIVE, a "Test Webhook" button is visible and enabled. When it's ACTIVE, the button disappears and you can't test it.&lt;/P&gt;&lt;P&gt;3) Create your&amp;nbsp;webhook file in your application and copy and paste the code below.&lt;/P&gt;&lt;P&gt;4)&amp;nbsp;Edit the code below where it reads &amp;lt;&amp;lt;put your Signature Key here&amp;gt;&amp;gt; and paste your Signature Key from Step 1 above.&lt;/P&gt;&lt;P&gt;5) Put your email address where it says &amp;lt;&amp;lt;your email address&amp;gt;&amp;gt; in both places.&amp;nbsp;&lt;/P&gt;&lt;P&gt;6) You can now TEST your webhook and have your code email you to let you know it succeeded or failed. I simply emailed the result to myself so I could verify the X-ANET signature matched the generated hash.&lt;/P&gt;&lt;P&gt;7) You're welcome.&amp;nbsp;;-)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;Imports System.IO&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;Imports System.Net.Mail&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;Imports System.Security.Cryptography&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;Partial Public Class webhook&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;Inherits System.Web.UI.Page&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;Public Shared Function ByteToString(ByVal buff As Byte()) As String&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;Dim sbinary As String = ""&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;For i As Integer = 0 To buff.Length - 1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;sbinary += buff(i).ToString("X2")&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;Next&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;Return (sbinary)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;End Function&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;Sub SubSendData(ByVal strEmail As String, ByVal strSubject As String, ByVal strBody As String)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;'Add the constant ToAddress&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;Const ToAddress As String = "&amp;lt;&amp;lt;your email address&amp;gt;&amp;gt;"&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;'(1) Create the MailMessage instance (from/to)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;Dim mm As New MailMessage(strEmail, ToAddress)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;'(2) Assign the MailMessage's properties&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;mm.Subject = strSubject&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;mm.Body = strBody&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;mm.IsBodyHtml = False&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;'(3) Create the SmtpClient object&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;Dim smtp As New SmtpClient&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;'(4) Send the MailMessage (will use the Web.config settings)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;'On Error Resume Next&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;smtp.Send(mm)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;End Sub&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;' Load Header collection into NameValueCollection object.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;Dim coll As NameValueCollection&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;coll = Request.Headers&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;Dim loop1, loop2 As Integer&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;Dim arr1(), arr2() As String&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;Dim strSha512 As String = ""&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;' Put the names of all keys into a string array.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;arr1 = coll.AllKeys&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;For loop1 = 0 To arr1.GetUpperBound(0)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;arr2 = coll.GetValues(loop1)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;' Get all values under this key.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;For loop2 = 0 To arr2.GetUpperBound(0)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;'the sha512 should be the last one in the array&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;'but to be sure let's check and exit when we find it&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;If InStr(arr2(loop2), "sha512") &amp;lt;&amp;gt; 0 Then&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;strSha512 = Server.HtmlEncode(arr2(loop2))&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;Exit For&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;End If&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;Next loop2&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;Next loop1&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;If strSha512 &amp;lt;&amp;gt; "" Then 'we found the X-ANET signature so continue&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;strSha512 = Replace(strSha512, "sha512=", "")&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;' now get the incoming stream body&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;Dim strInputStream As String&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;Dim streamReceive As Stream = Request.InputStream&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;Dim reader As StreamReader = New StreamReader(streamReceive, Encoding.UTF8)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;strInputStream = reader.ReadToEnd&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;' calculate the fingerprint&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;Dim strKeyText As String = "&amp;lt;&amp;lt;put your Signature Key here&amp;gt;&amp;gt;"&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;Dim encASCII As ASCIIEncoding = New ASCIIEncoding()&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;Dim bytKeyText As Byte() = encASCII.GetBytes(strKeyText)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;Dim hmacsha As HMACSHA512 = New HMACSHA512(bytKeyText)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;Dim bytInputStream As Byte() = encASCII.GetBytes(strInputStream)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;Dim bytHashInputStream As Byte() = hmacsha.ComputeHash(bytInputStream)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;Dim strComputedHash As String = ByteToString(bytHashInputStream)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;'now we have both the gateway X-ANET Signature (strSha512) , and our client generated value (strComputedHash) to compare&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;SubSendData("&amp;lt;&amp;lt;your email address&amp;gt;&amp;gt;", "webhook fired", strInputStream &amp;amp; vbNewLine &amp;amp; vbNewLine &amp;amp; strSha512 &amp;amp; vbNewLine &amp;amp; vbNewLine &amp;amp; strComputedHash)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;If strSha512 = strComputedHash Then&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;'good to go so then do what we need&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;Else ' no match so do something else&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;End If&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;Else 'X-ANET signature (strSha512) is not found so abort&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;End If&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;End Sub&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;End Class&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 19:43:36 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/HMAC-SHA-512-hash-not-matching-in-webhook-callback/m-p/61197#M35687</guid>
      <dc:creator>Janga</dc:creator>
      <dc:date>2018-01-11T19:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: HMAC SHA-512 hash not matching in webhook callback</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/HMAC-SHA-512-hash-not-matching-in-webhook-callback/m-p/82772#M52159</link>
      <description>&lt;P&gt;private static string ByteToString(byte[] buff)&lt;BR /&gt;{&lt;BR /&gt;string sbinary = "";&lt;BR /&gt;for(var i=0; i&amp;lt;=buff.Length-1; i++)&lt;BR /&gt;{&lt;BR /&gt;sbinary += buff[i].ToString("X2");&lt;BR /&gt;}&lt;BR /&gt;return sbinary;&lt;BR /&gt;}&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ended having to use this instead of Convert.ToBase64String(payloadHashbytes).&lt;/P&gt;&lt;P&gt;byte[] keybytes = Encoding.UTF8.GetBytes(secret);&lt;/P&gt;&lt;P&gt;System.Security.Cryptography.HMACSHA512 hmac1 = new System.Security.Cryptography.HMACSHA512(keybytes);&lt;BR /&gt;byte[] payloadbytes = Encoding.UTF8.GetBytes(payload);&lt;BR /&gt;byte[] payloadhashbytes = hmac1.ComputeHash(payloadbytes);&lt;BR /&gt;//string hmacString = Convert.ToBase64String(payloadhashbytes); //this is not working...had to use below ByteToString method&lt;BR /&gt;string hmacString = ByteToString(payloadhashbytes);&lt;BR /&gt;return hmacString;&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2022 16:11:04 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/HMAC-SHA-512-hash-not-matching-in-webhook-callback/m-p/82772#M52159</guid>
      <dc:creator>Harini</dc:creator>
      <dc:date>2022-05-19T16:11:04Z</dc:date>
    </item>
    <item>
      <title>Re: HMAC SHA-512 hash not matching in webhook callback</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/HMAC-SHA-512-hash-not-matching-in-webhook-callback/m-p/82773#M52160</link>
      <description>&lt;P&gt;byte[] keybytes = Encoding.UTF8.GetBytes(secret);&lt;/P&gt;&lt;P&gt;byte[] payloadbytes = Encoding.UTF8.GetBytes(payload);&lt;BR /&gt;byte[] payloadhashbytes = hmac1.ComputeHash(payloadbytes);&lt;BR /&gt;//string hmacString = Convert.ToBase64String(payloadhashbytes); //this is not working...had to use below ByteToString method&lt;BR /&gt;string hmacString = ByteToString(payloadhashbytes);&lt;BR /&gt;return hmacString;&lt;/P&gt;&lt;P&gt;This is C# version of Janga's code above which is working for me.&lt;/P&gt;&lt;P&gt;private static string ByteToString(byte[] buff)&lt;BR /&gt;{&lt;BR /&gt;string sbinary = "";&lt;BR /&gt;for(var i=0; i&amp;lt;=buff.Length-1; i++)&lt;BR /&gt;{&lt;BR /&gt;sbinary += buff[i].ToString("X2");&lt;BR /&gt;}&lt;BR /&gt;return sbinary;&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2022 16:15:57 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/HMAC-SHA-512-hash-not-matching-in-webhook-callback/m-p/82773#M52160</guid>
      <dc:creator>Harini</dc:creator>
      <dc:date>2022-05-19T16:15:57Z</dc:date>
    </item>
  </channel>
</rss>

