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

Example of a signature using the blockchain module.

See Note on examples.
using Dinamo.Hsm;
using System;
using System.Text;
using System.IO;
namespace BchainSignHash
{
class Program
{
private static String addr = "127.0.0.1";
private static String userId = "master";
private static String userPwd = "12345678";
static void Main(string[] args)
{
String keyId = "key";
try {
/*
Connect to HSM
*/
api.Connect(addr, userId, userPwd);
Console.Out.WriteLine("Connected successfully!");
/*
Generates the XPriv BIP-32 key.
*/
api. BchainCreateXPrvBip32(keyId, DinamoApi.DN_BCHAIN_VER_BIP32_MAINNET, false, false);
Console.Out.WriteLine("Key generated successfully!");
/*
Hash to be signed. Keccack-256 from the text "12345678".
The hash should ideally be generated in software external to the HSM.
*/
var hash = new byte[] { 0xa9, 0x22, 0x4f, 0xaa, 0x7b, 0xc2, 0x36, 0x09,
0x1f, 0x61, 0x53, 0xe7, 0xce, 0x01, 0x3a, 0x1b,
0x0a, 0x2c, 0x80, 0x2c, 0x18, 0xa7, 0xce, 0xdf,
0xeb, 0x70, 0x8f, 0x21, 0x17, 0x35, 0x90, 0x32 };
/*
Signs the hash with the previously generated private key.
*/
var signature = api. BchainSignHash(DinamoApi.DN_BCHAIN_SIG_DER_ECDSA,
hash, keyId);
Console.Out.WriteLine("Signature: " + BitConverter.ToString(signature));
} catch (DinamoException e) {
Console.Out.WriteLine(e.Message);
} finally{
/*
Disconnects from HSM
*/
api.Disconnect();
Console.Out.WriteLine("Successfully disconnected!");
}
}
}
}
Low-level class for accessing the HSM. To use this class you need to understand more ...
Definition DinamoApi.cs:15
const byte DN_BCHAIN_SIG_DER_ECDSA
Definition DinamoApi.cs:2483
const byte DN_BCHAIN_VER_BIP32_MAINNET
Definition DinamoApi.cs:2394
const byte DN_BCHAIN_HASH_KECCAK256
Definition DinamoApi.cs:2492
API class for accessing HSM functionalities Dinamo. In this class you can program using...
Definition DinamoClient.cs:93
Exception class for errors from Dinamo.
Definition DinamoException.cs:10
override string Message
Definition DinamoException.cs:42
void BchainCreateXPrvBip32(string szId, byte bVersion, bool isExportable, bool isTemporary)
Creates an XPriv private key in BIP32 format.
Definition DinamoClient.cs:7016
byte[] BchainSignHash(byte bType, byte bHashMode, byte[] pbHash, string szPk)
Sign a hash using the Blockchain module.
Definition DinamoClient.cs:7113
void RemoveObjectIfExists(string ObjectId)
Removes an object from the HSM, if it exists.
Definition DinamoClient.cs:2410
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