VB.NET sample code for the signature calculation



Option Explicit On
Option Strict On

Imports System
Imports System.Security.Cryptography
Imports System.Text

Namespace SignCmd
	Public Module CmdSigner
		Public Function SignedCommand(ByVal itemToCheck As String, ByVal keyString As String) As String
			Dim encoding As ASCIIEncoding = New ASCIIEncoding()

			'converting key to bytes will throw an exception, need to replace "minus" and "underscore" characters first.'
			Dim privateKeyBytes As Byte() = Convert.FromBase64String(keyString.Replace("-", "+").Replace("_", "/"))
			Dim encodedPathAndQueryBytes As Byte() = encoding.GetBytes(itemToCheck)

			'compute the hash'
			Dim algorithm As HMACSHA1 = New HMACSHA1(privateKeyBytes)
			Dim hash As Byte() = algorithm.ComputeHash(encodedPathAndQueryBytes)

			'convert the bytes to string and make url-safe by replacing '+' and '/' characters'
			Dim signature As String = Convert.ToBase64String(hash).Replace("+", "-").Replace("/", "_")

			'Return the signature.'
			Return signature
		End Function
	End Module
	Public Module Program
		Sub Main()
			Const keyString As String = "YOUR_PRIVATE_KEY"
			Dim cmdString As String = "COMMAND_ITEM_TO_SIGN"
			Console.WriteLine(CmdSigner.SignedCommand(cmdString, keyString))
		End Sub
	End Module
End Namespace
Terms Of Use | Privacy Statement | Company info
  • © Cedac Sistemi srl
  • Head office: Via Toscana, 3 40035 Castiglione dei Pepoli (Italy) Tel.: +39 0534-93811 Fax: +39 0534-93899
  • Branch office: Via del Lavoro, 47 40033 Casalecchio di Reno (Italy)
  • Branch office: Via Parini, 1 40033 Casalecchio di Reno (Italy)
  • Share capital Euro 26,000.00 - Company Register of Bologna / VAT no / fiscal code 01695261204