Example of export and import in TR-31 format.
#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;
char szKbpk[] = "kbpk";
char szKey[] = "key";
char szImpKey[] = "impKey";
if (nRet) {
printf("Function failure: DInitialize \nError code: %d\n", nRet);
goto clean;
}
printf("Libraries initialized.\n");
strncpy(authPwd.
szAddr, HOST_ADDR,
sizeof(authPwd
.szAddr));
strncpy(authPwd.
szUserId, USER_ID,
sizeof(authPwd
.szUserId));
strncpy(authPwd.
szPassword, USER_PWD,
sizeof(authPwd
.szPassword));
if (nRet) {
printf("Function failure: DOpenSession \nError code: %d\n", nRet);
goto clean;
}
printf("Session with Dinamo established.\n");
if (nRet)
{
printf("Function failure: DGenerateKey \nError code: %d\n", nRet);
goto clean;
}
if (nRet)
{
printf("Function failure: DGenerateKey \nError code: %d\n", nRet);
goto clean;
}
pbKeyBlock = malloc(dwKeyBlockLen);
if(pbKeyBlock == NULL)
{
printf("Failed to allocate memory\n");
goto clean;
}
if (nRet) {
printf("Function failure: DEFTExportTR31 \nError code: %d\n", nRet);
goto clean;
}
printf("Key exported successfully.\n");
dwKeyBlockLen, 0);
if (nRet)
{
printf("Function failure: DEFTImportTR31 \nError code: %d\n", nRet);
goto clean;
}
printf("Key imported successfully.\n");
clean:
if (hSession) {
printf("Session closed.\n");
}
free(pbKeyBlock);
printf("Libraries finished.\n");
return nRet;
}
HSM Application Programming Interface (API) Dinamo.
void * HSESSIONCTX
Definition dinamo.h:68
#define DEFAULT_PORT
Definition dinamo.h:1948
#define ALG_AES_256
Definition dinamo.h:1028
unsigned char BYTE
Definition dinamo.h:45
#define EFT_ME_TR31_EXP_USAGE_AUTO
Definition dinamo.h:1593
unsigned int DWORD
Definition dinamo.h:46
#define EFT_ME_TR31_EXP_AUTO
Definition dinamo.h:1647
#define ENCRYPTED_CONN
Definition dinamo.h:585
#define SS_USER_PWD
Definition dinamo.h:576
#define EFT_ME_TR31_EXP_MODE_AUTO
Definition dinamo.h:1633
#define ALG_AES_128
Definition dinamo.h:1026
void * HKEYCTX
Definition dinamo.h:70
#define EXPORTABLE_KEY
Definition dinamo.h:1422
int AAP_API DEFTImportTR31(HSESSIONCTX hSession, const char *szKBPK, const char *szKey, DWORD dwKeyAttributes, BYTE *pbKeyBlock, DWORD dwKeyBlockLen, DWORD dwParam)
int AAP_API DEFTExportTR31(HSESSIONCTX hSession, const char *szKBPK, const char *szKey, void *pvReserved, WORD wUsage, BYTE bMode, BYTE bExport, BYTE *pbOutBlock, DWORD *pdwOutBlockLen, DWORD dwParam)
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 nPort
Definition dinamo.h:3091
char szUserId[MAX_USR_LEN]
Definition dinamo.h:3092
char szAddr[MAX_ADDR_LEN]
Definition dinamo.h:3090
char szPassword[MAX_USR_PWD]
Definition dinamo.h:3093