Example of direct RSA encryption and decryption.
using System;
using System.IO;
namespace RSAEncDec
{
class Program
{
static void Main(string[] args)
{
string address = "127.0.0.1";
string user = "master";
string pass = "12345678";
string keyId = "key_id";
true);
byte[] data = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
byte[] buffer = new byte[256];
data.CopyTo(buffer, 0);
Console.WriteLine("Dados entrada(len {0}): {1}", data.Length,
BitConverter.ToString(data));
byte[] pubKeyData = hsm.
ExportKey(keyHandle, IntPtr.Zero,
string pubKeyId = "rsa2048_pub";
IntPtr pubKeyHandle = hsm.
ImportKey(pubKeyId, IntPtr.Zero,
pubKeyData,
int outDataLen = data.Length;
Console.WriteLine("OutDataLen: {0}", outDataLen);
hsm.
Encrypt(pubKeyHandle, IntPtr.Zero,
true, 0,
null,
ref outDataLen, buffer.Length);
Console.WriteLine("Dados encriptados (len {0}): {1}", outDataLen,
BitConverter.ToString(buffer));
outDataLen = buffer.Length;
hsm.
Decrypt(keyHandle, IntPtr.Zero,
true, 0,
null,
ref outDataLen);
Console.WriteLine("Dados decriptados (len {0}): {1}", outDataLen,
BitConverter.ToString(buffer));
}
}
}
API class for accessing HSM functionalities Dinamo. In this class you can program using...
Definition DinamoClient.cs:93
KEY_ALG
Definition DinamoClient.cs:227
MODE_TYPE
Definition DinamoClient.cs:430
PADDING_TYPE
Definition DinamoClient.cs:437
BLOB_TYPE
Definition DinamoClient.cs:449
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 DestroyKey(IntPtr hKey)
Release key handle.
Definition DinamoClient.cs:1953
byte[] ExportKey(IntPtr hKey, IntPtr hKeyEncryptionKey, BLOB_TYPE BlobType)
Definition DinamoClient.cs:2648
IntPtr ImportKey(string KeyId, IntPtr hKeyEncryptionKey, byte[] byKeyBlob, BLOB_TYPE BlobType, KEY_ALG AlgId)
Definition DinamoClient.cs:2668
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