NET API
HSM Dinamo
Loading...
Looking for...
No entries found
generate_hmac.cs

Example of the use of HMAC generation.

See Note on examples.
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";
//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();
}
}
}
API class for accessing HSM functionalities Dinamo. In this class you can program using...
Definition DinamoClient.cs:93
KEY_ALG
Definition DinamoClient.cs:227
HASH_ALG
Hash algorithm for signatures.
Definition DinamoClient.cs:137
void initMAC(HASH_ALG AlgId, String KeyId, int Flags)
Initializes a MAC operation in parts. It must be finalized with endMAC.
Definition DinamoClient.cs:3824
byte[] generateMAC(HASH_ALG AlgId, String KeyId, byte[] Data, int Flags)
Generates a MAC in just one call.
Definition DinamoClient.cs:3797
byte[] endMAC()
Ends a MAC operation.
Definition DinamoClient.cs:3859
void updateMAC(byte[] Data)
Updates a MAC operation with more data.
Definition DinamoClient.cs:3848
IntPtr GenerateKey(string KeyId, DinamoClient.KEY_ALG Alg, bool Exportable)
Generates a permanent key in the HSM.
Definition DinamoClient.cs:1891
void RemoveObject(string ObjectId)
Removes an object from the HSM.
Definition DinamoClient.cs:2397
void Connect(string User, string Password)
Establishes an encrypted connection to the HSM using the load balance settings.
Definition DinamoClient.cs:562
void Disconnect(bool flagClose)
Terminates the connection to the HSM.
Definition DinamoClient.cs:814
Namespace denoting a set of functions for accessing the HSM Dinamo and their respective exceptions.
Definition DinamoClient.cs:12
Definition DinamoClient.cs:12