API C/C++
HSM Dinamo
Loading...
Looking for...
No entries found
get_pub_key_bchain.c

Example of exporting a blockchain public key.

See Note on examples.
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "dinamo.h" /* header do Dinamo */
#define HOST_ADDR "127.0.0.1"
#define USER_ID "master"
#define USER_PWD "12345678"
int main()
{
int nRet = 0;
struct AUTH_PWD authPwd;
HSESSIONCTX hSession = NULL;
char szId[] = "Chave_Teste";
DWORD dwKeyLen = 0;
//Inicializa as bibliotecas do Dinamo
nRet = DInitialize(0);
if (nRet)
{
printf("Falha na funcao: DInitialize \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Bibliotecas inicializadas.\n");
//Inicializa a estrutura para conexao com o HSM
strncpy(authPwd.szAddr, HOST_ADDR, sizeof(authPwd.szAddr));
authPwd.nPort = DEFAULT_PORT;
strncpy(authPwd.szUserId, USER_ID, sizeof(authPwd.szUserId));
strncpy(authPwd.szPassword, USER_PWD, sizeof(authPwd.szPassword));
nRet = DOpenSession(&hSession, SS_USER_PWD, (BYTE *)&authPwd,
sizeof(authPwd), ENCRYPTED_CONN);
if (nRet)
{
printf("Falha na funcao: DOpenSession \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Sessao com o Dinamo estabelecida.\n");
//Cria chave de testes
nRet = DBchainCreateXPrv(hSession,
szId,
&ver,
sizeof(ver),
0);
if(nRet)
{
printf("Falha na funcao: DBchainCreateXPrv \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Chave Bip 32 criada com sucesso.\n");
//Exporta chave pública
nRet = DBchainGetPubKey(hSession,
szId,
NULL,
&dwKeyLen,
0);
if (nRet)
{
printf("Falha na funcao: DBchainGetPubKey \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Chave publica exportada com sucesso.\n");
clean:
nRet = DRemoveObj(hSession, szId);
if (nRet)
{
printf("Falha na funcao: DRemoveObj \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Chave Bchain removida do HSM.\n");
if (hSession) {
DCloseSession(&hSession, 0);
printf("Sessao encerrada.\n");
}
printf("Bibliotecas finalizadas.\n");
return nRet;
}
Application Programming Interface (API) do HSM Dinamo.
void * HSESSIONCTX
Definição dinamo.h:68
#define DEFAULT_PORT
Definição dinamo.h:1934
#define DN_BCHAIN_PBK_BIP340
Definição dinamo.h:2205
#define DN_BCHAIN_MAX_PBK_LEN
Definição dinamo.h:2213
unsigned char BYTE
Definição dinamo.h:45
unsigned int DWORD
Definição dinamo.h:46
#define ENCRYPTED_CONN
Definição dinamo.h:570
#define SS_USER_PWD
Definição dinamo.h:561
#define DN_BCHAIN_VER_BIP32_TESTNET
Definição dinamo.h:3495
#define DN_BCHAIN_BIP32_XPRV
Definição dinamo.h:3490
#define EXPORTABLE_KEY
Definição dinamo.h:1408
int AAP_API DBchainCreateXPrv(HSESSIONCTX hSession, BYTE bType, DWORD dwAttributes, const char *szId, const BYTE *pcbData, DWORD dwDataLen, DWORD dwReserved)
int AAP_API DBchainGetPubKey(HSESSIONCTX hSession, BYTE bType, const char *cszId, BYTE *pbData, DWORD *pdwDataLen, DWORD dwReserved)
int AAP_API DRemoveObj(HSESSIONCTX hSession, char *szObjId)
int AAP_API DOpenSession(HSESSIONCTX *phSession, DWORD dwParam, BYTE *pbData, DWORD dwDataLen, DWORD dwFlags)
int AAP_API DCloseSession(HSESSIONCTX *phSession, DWORD dwFlags)
int AAP_API DInitialize(DWORD dwReserved)
int AAP_API DFinalize()
Definição dinamo.h:3110
int nPort
Definição dinamo.h:3112
char szUserId[MAX_USR_LEN]
Definição dinamo.h:3113
char szAddr[MAX_ADDR_LEN]
Definição dinamo.h:3111
char szPassword[MAX_USR_PWD]
Definição dinamo.h:3114