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

Example of locking and unlocking an object.

See Note on examples.
using System;
using System.IO;
using Dinamo.Hsm;
namespace BlockObject
{
class Program
{
static void Main(string[] args)
{
string address = "127.0.0.1";
string user = "master";
string pass = "12345678";
//Conecta ao HSM
hsm.Connect(address, user, pass);
/*
Generate a test key and then run a test.
*/
string keyId = "key_id";
IntPtr keyHandle = hsm.GenerateKey(keyId, DinamoClient.KEY_ALG.ALG_RSA_2048, true);
//O handle da chave não será mais necessário neste teste.
hsm.DestroyKey(keyHandle);
Console.WriteLine("\nTest newly created key.");
Console.WriteLine("Chave bloqueada: {0}",
hsm.IsObjectBlocked(keyId));
TestAsymKeyAccess(hsm, keyId);
/*
Lock and test the key.
*/
Console.WriteLine("\nTest key locked.");
hsm.BlockObject(keyId, true);
Console.WriteLine("Chave bloqueada: {0}",
hsm.IsObjectBlocked(keyId));
TestAsymKeyAccess(hsm, keyId);
/*
Unlock and test the key.
*/
Console.WriteLine("\nTest key unlocked.");
hsm.BlockObject(keyId, false);
Console.WriteLine("Chave bloqueada: {0}",
hsm.IsObjectBlocked(keyId));
TestAsymKeyAccess(hsm, keyId);
/*
Remove the test key and disconnect from the HSM.
*/
hsm.RemoveObject(keyId);
hsm.Disconnect();
}
static void TestAsymKeyAccess(DinamoClient hsm, string keyId)
{
var data = new byte[] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 };
try{
hsm.SignHash(keyId, data, DinamoClient.HASH_ALG.ALG_SHA2_256);
}catch (DinamoException e)
{
Console.WriteLine("Sign hash failed: " + e.Message);
return;
}
Console.WriteLine("Key tested successfully.");
}
}
}
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
Exception class for errors from Dinamo.
Definition DinamoException.cs:10
override string Message
Definition DinamoException.cs:42
byte[] SignHash(String keyId, byte[] bHash, DinamoClient.HASH_ALG algHash)
Sign a hash.
Definition DinamoClient.cs:4035
bool IsObjectBlocked(string szObjectName)
Recovers the locked state of an object.
Definition DinamoClient.cs:2354
void DestroyKey(IntPtr hKey)
Release key handle.
Definition DinamoClient.cs:1953
void BlockObject(string szObjectName, bool bBlock)
Changes the lock status of an object.
Definition DinamoClient.cs:2321
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