Example of tokenization with the SVault module using token generation and secret recovery.
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define HOST_ADDR "127.0.0.1"
#define USER_ID "master"
#define USER_PWD "12345678"
int main()
{
int nRet = 0;
#define PROTECTION_KEY_NAME "aes256"
char szMK[] = PROTECTION_KEY_NAME;
DWORD dwTokenBlobLen =
sizeof(pbTokenBlob);
DWORD dwSecretLen =
sizeof(szSecret);
if (nRet) {
printf("Falha na funcao: DInitialize \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Bibliotecas inicializadas.\n");
if (nRet) {
printf("Falha na funcao: DOpenSession \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Sessao com o Dinamo estabelecida.\n");
{
"26122200468",
PROTECTION_KEY_NAME};
0,
pbTokenBlob,
&dwTokenBlobLen,
szToken,
0);
if (nRet)
{
printf("Falha na funcao: DSVaultGenToken \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Token (CPF) gerado com sucesso. \"%s\".\n", szToken);
PROTECTION_KEY_NAME,
NULL,
pbTokenBlob,
dwTokenBlobLen,
szSecret,
&dwSecretLen,
0);
if (nRet) {
printf("Falha na funcao: DSVaultGetData (CPF) \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Secret (CPF) recuperado com sucesso. \"%s\".\n", szSecret);
#define CPF_MASK "***\0\0\0***"
memcpy(szMask, CPF_MASK, sizeof(CPF_MASK));
dwSecretLen = sizeof(szSecret);
PROTECTION_KEY_NAME,
szMask,
pbTokenBlob,
dwTokenBlobLen,
szSecret,
&dwSecretLen,
0);
if (nRet)
{
printf("Falha na funcao: DSVaultGetData (CPF) \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Secret (CPF) recuperado com sucesso. \"%s\".\n", szSecret);
}
{
"Este \xc3\xA9 um teste",
PROTECTION_KEY_NAME};
dwTokenBlobLen = sizeof(pbTokenBlob);
0,
(
BYTE *)&stTokenInfoString,
pbTokenBlob,
&dwTokenBlobLen,
szToken,
0);
if (nRet)
{
printf("Falha na funcao: DSVaultGenToken (string) \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Token (string) gerado com sucesso. \"%s\".\n", szToken);
dwSecretLen = sizeof(szSecret);
PROTECTION_KEY_NAME,
NULL,
pbTokenBlob,
dwTokenBlobLen,
szSecret,
&dwSecretLen,
0);
if (nRet)
{
printf("Falha na funcao: DSVaultGetData (string) \nCodigo de erro: %d\n", nRet);
goto clean;
}
#ifdef _WIN32
SetConsoleOutputCP(CP_UTF8);
#endif
printf("Secret (string) recuperado com sucesso. \"%s\".\n", szSecret);
memset(szMask, 0, sizeof(szMask));
#define TEXT_MASK "*******\0\0\0"
memcpy(szMask, TEXT_MASK, sizeof(TEXT_MASK));
dwSecretLen = sizeof(szSecret);
PROTECTION_KEY_NAME,
szMask,
pbTokenBlob,
dwTokenBlobLen,
szSecret,
&dwSecretLen,
0);
if (nRet)
{
printf("Falha na funcao: DSVaultGetData (string) \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Secret (string) recuperado com sucesso. \"%s\".\n", szSecret);
}
clean:
if (hSession) {
printf("Sessao encerrada.\n");
}
printf("Bibliotecas finalizada.\n");
return nRet;
}
Application Programming Interface (API) do HSM Dinamo.
#define D_SVAULT_TOKEN_BLOB_LEN
Definição dinamo.h:2113
void * HSESSIONCTX
Definição dinamo.h:68
#define DEFAULT_PORT
Definição dinamo.h:1949
#define ALG_AES_256
Definição dinamo.h:1029
#define D_SVAULT_GET_OP_SECRET
Definição dinamo.h:2117
#define D_SVAULT_MAX_TL
Definição dinamo.h:2094
#define D_SVAULT_CKS_NULL
Definição dinamo.h:2101
unsigned char BYTE
Definição dinamo.h:45
#define D_SVAULT_F_MASK_SECRET
Definição dinamo.h:2099
#define D_SVAULT_BASE62
Definição dinamo.h:2111
#define D_SVAULT_T_TKR2
Definição dinamo.h:2096
unsigned int DWORD
Definição dinamo.h:46
#define ENCRYPTED_CONN
Definição dinamo.h:585
#define SS_USER_PWD
Definição dinamo.h:576
#define D_SVAULT_BASE10
Definição dinamo.h:2107
#define D_SVAULT_CKS_CPF
Definição dinamo.h:2102
int AAP_API DGenerateKey(HSESSIONCTX hSession, char *szKeyId, int nAlgId, DWORD dwFlags, HKEYCTX *phKey)
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 DSVaultGetData(HSESSIONCTX hSession, DWORD dwOp, const char *szMK, const char *szMask, BYTE *pbTokenBlob, DWORD dwTokenBlobLen, char *szData, DWORD *pdwDataLen, DWORD dwReserved)
int AAP_API DSVaultGenToken(HSESSIONCTX hSession, DWORD dwOp, BYTE *pbInData, BYTE *pbTokenBlob, DWORD *pdwTokenBlobLen, char *szToken, DWORD dwReserved)
int nPort
Definição dinamo.h:3092
char szUserId[MAX_USR_LEN]
Definição dinamo.h:3093
char szAddr[MAX_ADDR_LEN]
Definição dinamo.h:3091
char szPassword[MAX_USR_PWD]
Definição dinamo.h:3094