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

Example of splitting and retrieving a secret using M from N.

See Note on examples.
using Dinamo.Hsm;
using System;
using System.Text;
using System.IO;
namespace MofN
{
class Program
{
private static String addr = "127.0.0.1";
static void Main(string[] args)
{
try {
/*
Connect using an anonymous session in HSM.
You don't need a user account to perform this operation.
*/
api.ConnectAnonymously(addr);
Console.Out.WriteLine("Successfully connected anonymously!");
/*
It divides the secret into an M of N scheme, where there is a set of
6 parts and 2 parts are needed to rebuild the secret.
In this case, as null was passed in the secret parameter, the secret is
randomly generated within the HSM.
*/
var splitInfo = api. MofNSplit(2, 6, null);
Console.Out.WriteLine("Secret split successfully!");
Console.Out.WriteLine("Secret: " + BitConverter.ToString(splitInfo.pbSecret).Replace("-", ""));
Console.Out.WriteLine("Total parts: " + splitInfo.dwPartCount);
for (UInt32 i = 0; i < splitInfo.dwPartCount; i++) {
Console.Out.WriteLine("Part " + (i + 1) + ": " + BitConverter.ToString(splitInfo.pstParts[i].pbPart).Replace("-", ""));
}
/*
Recover the secret from 2 parts.
*/
parts[0] = splitInfo.pstParts[0];
parts[1] = splitInfo.pstParts[1];
var recoveredSecret = api. MofNRecover(parts);
Console.Out.WriteLine("Secret successfully retrieved!");
Console.Out.WriteLine("Recovered secret: " + BitConverter.ToString(recoveredSecret).Replace("-", ""));
} 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
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
DinamoApi.DN_M_OF_N_SPLIT_INFO MofNSplit(byte bM, byte bN, byte[] pbSecret)
Divides M from N in a secret. According to Shamir's secret sharing pattern.
Definition DinamoClient.cs:4216
byte[] MofNRecover(DinamoApi.DN_M_OF_N_PART[] parts)
It reconstructs the secret M of N from the parts of the custodians. According to the sharing pattern...
Definition DinamoClient.cs:4239
void Disconnect(bool flagClose)
Terminates the connection to the HSM.
Definition DinamoClient.cs:814
void ConnectAnonymously(string Address)
Establishes an anonymous connection to the HSM.
Definition DinamoClient.cs:722
Namespace denoting a set of functions for accessing the HSM Dinamo and their respective exceptions.
Definition DinamoClient.cs:12
Definition DinamoApi.cs:2650