For others that may find this useful, below is my code to get it working in VB.NET with the SIM integration, with thanks to a few members on this forum...
Firstly I have a function to do the SHA512 (VB.NET modified version of the C# example Authorize.Net created)...
Public Shared Function GetAuthorizeNetHMACSHA512(ByVal key As String, ByVal textToHash As String)
If String.IsNullOrEmpty(key) Then Return ""
If String.IsNullOrEmpty(textToHash) Then Return ""
If Key.Length Mod 2 <> 0 OrElse Key.Trim().Length < 2 Then
Return ""
End If
Try
Dim k As Byte() = Enumerable.Range(0, Key.Length).Where(Function(x) x Mod 2 = 0).[Select](Function(x) Convert.ToByte(Key.Substring(x, 2), 16)).ToArray()
Dim hmac As System.Security.Cryptography.HMACSHA512 = New System.Security.Cryptography.HMACSHA512(k)
Dim HashedValue As Byte() = hmac.ComputeHash((New System.Text.ASCIIEncoding()).GetBytes(textToHash))
Return BitConverter.ToString(HashedValue).Replace("-", String.Empty)
Catch ex As Exception
Return ""
End Try
End Function
I generate the Sequence and TimeStamp as I always have done. The Fingerprint is generated by calling the new SHA512 function. This function passes in the API Login ID, Sequence, TimeStamp and Amount as follows and the Signature Key as the hash...
Dim Random As New Random
Dim Sequence = Random.Next(0, 1000)
Dim TimeStamp = CInt((DateTime.UtcNow - New DateTime(1970, 1, 1)).TotalSeconds)
Dim Fingerprint = GetAuthorizeNetHMACSHA512(anSignatureKey, anAPILoginID & "^" & Sequence & "^" & TimeStamp & "^" & Total.ToString("0.##") & "^")
When doing the initial post to Authorize.Net I generate the x_fp_sequence, x_fp_timestamp and x_fp_hash from the Sequence, TimeStamp and Finterprint variables shown above.
In the Relay Response URL I build up the text I want to hash based on the 30 reponse fields described on page 73 of the SIM guide. I then SHA512 this value using the same Signature Key. I finally get the x_SHA2_Hash from the response and compare this to the value I SHA512 hashed and deal with as appropriate...
Dim TextToHash As String = String.Join("^", Request.Params("x_trans_id"), Request.Params("x_test_request"), Request.Params("x_response_code"), Request.Params("x_auth_code"), Request.Params("x_cvv2_resp_code"), Request.Params("x_cavv_response"), Request.Params("x_avs_code"), Request.Params("x_method"), Request.Params("x_account_number"), Request.Params("x_amount"), Request.Params("x_company"), Request.Params("x_first_name"), Request.Params("x_last_name"), Request.Params("x_address"), Request.Params("x_city"), Request.Params("x_state"), Request.Params("x_zip"), Request.Params("x_country"), Request.Params("x_phone"), Request.Params("x_fax"), Request.Params("x_email"), Request.Params("x_ship_to_company"), Request.Params("x_ship_to_first_name"), Request.Params("x_ship_to_last_name"), Request.Params("x_ship_to_address"), Request.Params("x_ship_to_city"), Request.Params("x_ship_to_state"), Request.Params("x_ship_to_zip"), Request.Params("x_ship_to_country"), Request.Params("x_invoice_num"))
Dim HashedValue As String = PaymentRepository.GetAuthorizeNetHMACSHA512(anSignatureKey, "^" & TextToHash & "^")
Dim x_SHA2_Hash As String = Request.Params("x_SHA2_Hash").ToString()
If HashedValue <> x_SHA2_Hash Then
' Do as appropriate if they don't match
End If