Example of symmetric encryption and decryption using HSM.
using System;
using System.Collections.Generic;
using System.Text;
namespace TesteNF
{
class Program
{
static void Main(string[] args)
{
"master",
"12345678" );
string keyId = "aes256";
byte[] iv =
new byte[
DinamoApi.
AES_IV_LEN]{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte[] originalData = Encoding.ASCII.GetBytes("asdfasdfasdfasdfas");
Array.Copy(originalData, dataToEncrypt, originalData.Length);
int dataToEncryptLen = originalData.Length;
IntPtr.Zero,
true,
iv,
dataToEncrypt,
ref dataToEncryptLen,
dataToEncrypt.Length);
IntPtr.Zero,
true,
iv,
dataToEncrypt,
ref dataToEncryptLen );
Console.Out.WriteLine("Dado decriptado:\n {0}", System.Text.Encoding.Default.GetString(dataToEncrypt));
Console.In.ReadLine();
}
}
}
Low-level class for accessing the HSM. To use this class you need to understand more ...
Definition DinamoApi.cs:15
const Int32 AES_IV_LEN
Definition DinamoApi.cs:903
API class for accessing HSM functionalities Dinamo. In this class you can program using...
Definition DinamoClient.cs:93
MODE_TYPE
Definition DinamoClient.cs:430
PADDING_TYPE
Definition DinamoClient.cs:437
void Encrypt(IntPtr hKey, bool Final, byte[] byData, ref int DataLen, int BufferLen)
Encrypt blocks or files by passing the key reference. Uses default mode/padding,...
Definition DinamoClient.cs:3163
void Decrypt(string strKeyId, IntPtr hHash, bool Final, byte[] byData, ref int DataLen)
Decrypts a hash, general data or a file.
Definition DinamoClient.cs:3504
void Connect(string User, string Password)
Establishes an encrypted connection to the HSM using the load balance settings.
Definition DinamoClient.cs:562
Namespace denoting a set of functions for accessing the HSM Dinamo and their respective exceptions.
Definition DinamoClient.cs:12