有两种方式
1、通过安全代理服务器校验证书:
在发放Key时通过厂商提供的程序向Key中写入证书信息
2、自己通过API向Key中写入一些用于校验的信息,而且Key有自身的序列号
//贴一段用C写的例子给你
// sdkDemo.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <string.h>
#include <iostream.h>
#define GS_SUCCESS 0x00000000
#define GS_HW_ERROR 0x00000001
#define GS_ACCESS_DENIED 0x00000002
#define GS_DIR_NOT_FOUND 0x00000003
#define GS_FILE_NOT_FOUND 0x00000004
#define GS_ALREADY_EXISTS 0x00000005
#define GS_NOT_ENOUGH_MEMORY 0x00000006
#define GS_INVALID_PARAMETER 0x00000007
#define GS_USER_PIN_LEN_RANGE 0x00000008
#define GS_PIN_LOCKED 0x00000009
#define GS_PIN_INCORRECT 0x0000000a
#define GS_GENERAL_ERROR 0x0000000b
typedef unsigned long (WINAPI *p_CreateDir)(unsigned long);
typedef unsigned long (WINAPI *p_CreateFile)(unsigned long,
unsigned long);
typedef unsigned long (WINAPI *p_WriteFile)(unsigned long,
unsigned long,
unsigned char *,
int );
typedef unsigned long (WINAPI *p_ReadFile)(unsigned long,
unsigned long,
unsigned char *,
int *);
typedef bool (WINAPI *p_Encrypt)(unsigned char *,
unsigned char *,
int *);
typedef bool (WINAPI *p_Decrypt)(unsigned char *,
unsigned char *,
int *);
typedef unsigned long (WINAPI *p_ClearKey)(void);
typedef unsigned long (WINAPI *p_VerifyMasterPIN)(char *);
typedef unsigned long (WINAPI *p_RSASign)(unsigned char *,
unsigned char *,
int);
typedef unsigned long (WINAPI *p_RSAVerify)(unsigned char *,
unsigned char *,
unsigned char *,
int);
typedef bool (WINAPI *p_GetPublicKey)(unsigned char *);
typedef unsigned long (WINAPI *p_VerifyPIN)(char *pin);
typedef bool (WINAPI *p_GetTokenSN)(unsigned char *pbuffer);
int main(int argc, char* argv[])
{
HINSTANCE hinstLib;
unsigned long grv;
bool brv;
p_GetTokenSN GetTokenSN;
p_CreateDir CreateDir;
p_CreateFile CreateFile;
p_WriteFile WriteFile;
p_ReadFile ReadFile;
p_Encrypt EncryptData;
p_Decrypt DecryptData;
p_ClearKey ClearKey;
p_VerifyMasterPIN VerifyMasterPIN;
//p_RSASign RSASign;
//p_RSAVerify RSAVerify;
//p_GetPublicKey GetPublicKey;
//p_VerifyPIN VerifyPIN;
unsigned long dirID = 12;
unsigned long fileID = 10;
unsigned char plainBuffer1[] = "1234567890";
unsigned char cipherBuffer[30];
unsigned char plainBuffer2[30];
unsigned char tempBuffer[30];
unsigned char pSN [16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int length = strlen((char *)plainBuffer1);
int readLen;
//装载位于指定目录下的SDK开发包
hinstLib = LoadLibrary("jxkeysdk.dll"
;
if(hinstLib == NULL)
{
printf("动态库装载失败!/n"
;
return 0;
}
printf("动态库装载成功!/n"
;
//取序列号
GetTokenSN = (p_GetTokenSN)GetProcAddress(hinstLib, "GS_GetTokenSN"
;
if(GetTokenSN == NULL)
{
printf("加载函数GS_GetTokenSN失败!/n"
;
return 0;
}
printf("加载函数GS_GetTokenSN成功!/n"
;
if (GetTokenSN(pSN)) {
for (int ii=0;ii<=15;ii++)
printf("%02x ", pSN[ii]);
printf("/r/n"
;
}
//验证MasterPIN码
VerifyMasterPIN = (p_VerifyMasterPIN)GetProcAddress(hinstLib, "GS_VerifyMasterPIN"
;
if(VerifyMasterPIN == NULL)
{
printf("加载函数GS_VerifyMasterPIN失败!/n"
;
return 0;
}
printf("加载函数GS_VerifyMasterPIN成功!/n"
;
grv = (VerifyMasterPIN)("1111"
;
if(grv != GS_SUCCESS)
{
printf("验证MasterPIN码失败!/n"
;
return 0;
}
printf("验证MasterPIN码成功!/n"
;
//初始化
ClearKey = (p_ClearKey)GetProcAddress(hinstLib, "GS_ClearKey"
;
if(ClearKey == NULL)
{
printf("加载函数GS_ClearKey失败!/n"
;
return 0;
}
printf("加载函数GS_ClearKey成功!/n"
;
grv = (ClearKey)();
if(grv != GS_SUCCESS)
{
printf("初始化失败!/n"
;
return 0;
}
printf("初始化成功!/n"
;
//创建目录
CreateDir = (p_CreateDir)GetProcAddress(hinstLib, "GS_CreateDir"
;
if(CreateDir == NULL)
{
printf("加载函数GS_CreateDir失败!/n"
;
return 0;
}
printf("加载函数GS_CreateDir成功!/n"
;
grv = (CreateDir)(dirID);
if(grv != GS_SUCCESS)
{
printf("创建目录失败!/n"
;
return 0;
}
printf("创建目录成功!/n"
;
//创建文件
CreateFile = (p_CreateFile)GetProcAddress(hinstLib, "GS_CreateFile"
;
if(CreateFile == NULL)
{
printf("加载函数GS_CreateFile失败!/n"
;
return 0;
}
printf("加载函数GS_CreateFile成功!/n"
;
grv = (CreateFile)(dirID,fileID);
if(grv != GS_SUCCESS)
{
printf("创建文件失败!/n"
;
return 0;
}
printf("创建文件成功!/n"
;
//加密数据
EncryptData = (p_Encrypt)GetProcAddress(hinstLib, "GS_Encrypt"
;
if(EncryptData == NULL)
{
printf("加载函数GS_Encrypt失败!/n"
;
return 0;
}
printf("加载函数GS_Encrypt成功!/n"
;
brv = (EncryptData)(plainBuffer1, cipherBuffer, &length);
if(!brv)
{
printf("加密数据失败!/n"
;
return 0;
}
printf("加密数据成功:%s -> %s/n", plainBuffer1, cipherBuffer);
//向文件中写入密文
WriteFile = (p_WriteFile)GetProcAddress(hinstLib, "GS_WriteFile"
;
if(WriteFile == NULL)
{
printf("加载函数GS_WriteFile失败!/n"
;
return 0;
}
printf("加载函数GS_WriteFile成功!/n"
;
grv = (WriteFile)(dirID,fileID,cipherBuffer,length);
if(grv != GS_SUCCESS)
{
printf("写文件失败!/n"
;
return 0;
}
printf("写文件成功:%s/n", cipherBuffer);
//从文件中读出数据
ReadFile = (p_ReadFile)GetProcAddress(hinstLib, "GS_ReadFile"
;
if(ReadFile == NULL)
{
printf("加载函数GS_ReadFile失败!/n"
;
return 0;
}
printf("加载函数GS_ReadFile成功!/n"
;
readLen = 100;
grv = (ReadFile)(dirID,fileID,tempBuffer,&readLen);
if(grv != GS_SUCCESS)
{
printf("读文件失败!/n"
;
return 0;
}
printf("读文件成功:%s/n", tempBuffer);
//解密数据
DecryptData = (p_Decrypt)GetProcAddress(hinstLib, "GS_Decrypt"
;
if(DecryptData == NULL)
{
printf("加载函数GS_Decrypt失败!/n"
;
return 0;
}
printf("加载函数GS_Decrypt成功:%s/n", DecryptData);
brv = (DecryptData)(tempBuffer, plainBuffer2, &readLen);
if(!brv)
{
printf("解密数据失败!/n"
;
return 0;
}
printf("解密数据成功!/n"
;
/*
//校验PIN码
VerifyPIN = (p_VerifyPIN)GetProcAddress(hinstLib, "GS_VerifyPIN"
;
if(VerifyPIN == NULL)
{
printf("加载函数GS_VerifyPIN失败!/n"
;
return 0;
}
printf("加载函数GS_VerifyPIN成功!/n"
;
grv = (VerifyPIN)("1111"
;
if(grv!=GS_SUCCESS)
{
printf("校验PIN码失败!/n"
;
return 0;
}
printf("校验PIN码成功!/n"
;
//对数据进行签名
unsigned char signBuffer[128];
RSASign = (p_RSASign)GetProcAddress(hinstLib, "GS_RSASign"
;
if(RSASign == NULL)
{
printf("加载函数GS_RSASign失败!/n"
;
return 0;
}
printf("加载函数GS_RSASign成功!/n"
;
grv = (RSASign)(plainBuffer1, signBuffer, 10);
if(grv != GS_SUCCESS)
{
printf("数据签名失败!/n"
;
return 0;
}
printf("数据签名成功!/n"
;
//获取公钥
unsigned char pukBuffer[128];
GetPublicKey = (p_GetPublicKey)GetProcAddress(hinstLib, "GS_GetPublicKey"
;
if(GetPublicKey == NULL)
{
printf("加载函数GS_GetPublicKey失败!/n"
;
return 0;
}
printf("加载函数GS_GetPublicKeyy成功!/n"
;
brv = (GetPublicKey)(pukBuffer);
if(!brv)
{
printf("获取公钥失败!/n"
;
return 0;
}
printf("获取公钥成功!/n"
;
//验证数据签名
RSAVerify = (p_RSAVerify)GetProcAddress(hinstLib, "GS_RSAVerify"
;
if(RSAVerify == NULL)
{
printf("加载函数GS_RSAVerify失败!/n"
;
return 0;
}
printf("加载函数GS_RSAVerify成功!/n"
;
grv = (RSAVerify)(signBuffer, plainBuffer1, pukBuffer, 10);
if(grv != GS_SUCCESS)
{
printf("数据签名错误!/n"
;
return 0;
}
printf("数据签名正确!/n"
;
*/
FreeLibrary(hinstLib);
return 0;
}