API .Net HSM Dinamo
API Proprietária .Net do HSM Dinamo
generate_hmac.cs

Exemplo de uso de geração HMAC.

Veja Nota sobre os exemplos.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dinamo;
using Dinamo.Hsm;
namespace GenerateMAC
{
class Program
{
static void Main(string[] args)
{
string address = "10.0.0.1";
string user = "master";
string pass = "12345678";
DinamoClient din = new DinamoClient();
//Conecta ao HSM
din.Connect(address, user, pass);
string hmacKeyName = "hmac_key";
Console.Out.WriteLine("Generate HMAC key:\n {0}", hmacKeyName);
din.RemoveObject(hmacKeyName);
din.GenerateKey(hmacKeyName, DinamoClient.KEY_ALG.ALG_HMAC_SHA2_256, true);
byte []message1 = new byte[]
{
0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38
};
byte []message2 = new byte[]
{
0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31,
0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32,
};
Console.Out.WriteLine("Generate HMAC in one call.\n");
byte[] hmac = din.generateMAC(DinamoClient.HASH_ALG.ALG_HMAC_SHA2_256, hmacKeyName, message1);
Console.Out.WriteLine("hmac: {0}\n", BitConverter.ToString(hmac).Replace("-", string.Empty));
Console.Out.WriteLine("Generate HMAC in multiple calls.\n");
din.initMAC(DinamoClient.HASH_ALG.ALG_HMAC_SHA2_256, hmacKeyName);
din.updateMAC(message1);
din.updateMAC(message2);
byte[] hmac2 = din.endMAC();
Console.Out.WriteLine("hmac2: {0}\n", BitConverter.ToString(hmac2).Replace("-", string.Empty));
din.Disconnect();
}
}
}
Namespace que denota um conjunto de funções para acesso ao HSM Dinamo e suas respectivas exceptions.
Definition: DinamoClient.cs:12
Definition: DinamoClient.cs:12