Reconstructing a secret in M from N
// Importa o cliente Dinamo HSM
const { hsm } = require("@dinamonetworks/hsm-dinamo");
// Define os parâmetros de conexão com o HSM
const options = {
host: "127.0.0.1",
authUsernamePassword: {
username: "master",
password: "12345678",
},
};
async function mOfNRecover() {
// Connecta ao HSM
const conn = await hsm.connect(options);
// Segredo a ser dividido
const secret = "secretToBeDividedInParts";
// Divisão M de N de um segredo
const M = 2;
const N = 3;
const division = await conn.cryptography.mOfnSplit(M, N, secret);
// Recupera o segredo
const reconstructedSecret = await conn.cryptography.mOfNRecover(
division.parts
);
// Segredo reconstruído
console.log(reconstructedSecret.toString());
// Desconecta do HSM
await conn.disconnect();
}
// Execute a função mOfNRecover
mOfNRecover();