哪位大虾开发过usbkey程序?本人急需,300分狂求(300分)

  • 主题发起人 主题发起人 盲流
  • 开始时间 开始时间

盲流

Unregistered / Unconfirmed
GUEST, unregistred user!
哪位大虾开发过usbkey程序?本人急需,300分狂求
 
我们用C/S/S方式
就是调API
不知道你用的是哪家的Key
 
楼上的大哥,具体还没定。在这方面我是阿白,能否给我推荐一下?
 
有两种方式
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[] = &quot;1234567890&quot;;
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(&quot;jxkeysdk.dll&quot;);
if(hinstLib == NULL)
{
printf(&quot;动态库装载失败!/n&quot;);
return 0;
}
printf(&quot;动态库装载成功!/n&quot;);
//取序列号
GetTokenSN = (p_GetTokenSN)GetProcAddress(hinstLib, &quot;GS_GetTokenSN&quot;);
if(GetTokenSN == NULL)
{
printf(&quot;加载函数GS_GetTokenSN失败!/n&quot;);
return 0;
}
printf(&quot;加载函数GS_GetTokenSN成功!/n&quot;);
if (GetTokenSN(pSN)) {
for (int ii=0;ii<=15;ii++)
printf(&quot;%02x &quot;, pSN[ii]);
printf(&quot;/r/n&quot;);
}
//验证MasterPIN码
VerifyMasterPIN = (p_VerifyMasterPIN)GetProcAddress(hinstLib, &quot;GS_VerifyMasterPIN&quot;);
if(VerifyMasterPIN == NULL)
{
printf(&quot;加载函数GS_VerifyMasterPIN失败!/n&quot;);
return 0;
}
printf(&quot;加载函数GS_VerifyMasterPIN成功!/n&quot;);

grv = (VerifyMasterPIN)(&quot;1111&quot;);
if(grv != GS_SUCCESS)
{
printf(&quot;验证MasterPIN码失败!/n&quot;);
return 0;
}
printf(&quot;验证MasterPIN码成功!/n&quot;);

//初始化
ClearKey = (p_ClearKey)GetProcAddress(hinstLib, &quot;GS_ClearKey&quot;);
if(ClearKey == NULL)
{
printf(&quot;加载函数GS_ClearKey失败!/n&quot;);
return 0;
}
printf(&quot;加载函数GS_ClearKey成功!/n&quot;);
grv = (ClearKey)();
if(grv != GS_SUCCESS)
{
printf(&quot;初始化失败!/n&quot;);
return 0;
}
printf(&quot;初始化成功!/n&quot;);
//创建目录
CreateDir = (p_CreateDir)GetProcAddress(hinstLib, &quot;GS_CreateDir&quot;);
if(CreateDir == NULL)
{
printf(&quot;加载函数GS_CreateDir失败!/n&quot;);
return 0;
}
printf(&quot;加载函数GS_CreateDir成功!/n&quot;);
grv = (CreateDir)(dirID);
if(grv != GS_SUCCESS)
{
printf(&quot;创建目录失败!/n&quot;);
return 0;
}
printf(&quot;创建目录成功!/n&quot;);
//创建文件
CreateFile = (p_CreateFile)GetProcAddress(hinstLib, &quot;GS_CreateFile&quot;);
if(CreateFile == NULL)
{
printf(&quot;加载函数GS_CreateFile失败!/n&quot;);
return 0;
}
printf(&quot;加载函数GS_CreateFile成功!/n&quot;);
grv = (CreateFile)(dirID,fileID);
if(grv != GS_SUCCESS)
{
printf(&quot;创建文件失败!/n&quot;);
return 0;
}
printf(&quot;创建文件成功!/n&quot;);
//加密数据
EncryptData = (p_Encrypt)GetProcAddress(hinstLib, &quot;GS_Encrypt&quot;);
if(EncryptData == NULL)
{
printf(&quot;加载函数GS_Encrypt失败!/n&quot;);
return 0;
}
printf(&quot;加载函数GS_Encrypt成功!/n&quot;);
brv = (EncryptData)(plainBuffer1, cipherBuffer, &length);
if(!brv)
{
printf(&quot;加密数据失败!/n&quot;);
return 0;
}
printf(&quot;加密数据成功:%s -> %s/n&quot;, plainBuffer1, cipherBuffer);
//向文件中写入密文
WriteFile = (p_WriteFile)GetProcAddress(hinstLib, &quot;GS_WriteFile&quot;);
if(WriteFile == NULL)
{
printf(&quot;加载函数GS_WriteFile失败!/n&quot;);
return 0;
}
printf(&quot;加载函数GS_WriteFile成功!/n&quot;);
grv = (WriteFile)(dirID,fileID,cipherBuffer,length);
if(grv != GS_SUCCESS)
{
printf(&quot;写文件失败!/n&quot;);
return 0;
}
printf(&quot;写文件成功:%s/n&quot;, cipherBuffer);
//从文件中读出数据
ReadFile = (p_ReadFile)GetProcAddress(hinstLib, &quot;GS_ReadFile&quot;);
if(ReadFile == NULL)
{
printf(&quot;加载函数GS_ReadFile失败!/n&quot;);
return 0;
}
printf(&quot;加载函数GS_ReadFile成功!/n&quot;);
readLen = 100;
grv = (ReadFile)(dirID,fileID,tempBuffer,&readLen);
if(grv != GS_SUCCESS)
{
printf(&quot;读文件失败!/n&quot;);
return 0;
}
printf(&quot;读文件成功:%s/n&quot;, tempBuffer);
//解密数据
DecryptData = (p_Decrypt)GetProcAddress(hinstLib, &quot;GS_Decrypt&quot;);
if(DecryptData == NULL)
{
printf(&quot;加载函数GS_Decrypt失败!/n&quot;);
return 0;
}
printf(&quot;加载函数GS_Decrypt成功:%s/n&quot;, DecryptData);
brv = (DecryptData)(tempBuffer, plainBuffer2, &readLen);
if(!brv)
{
printf(&quot;解密数据失败!/n&quot;);
return 0;
}
printf(&quot;解密数据成功!/n&quot;);
/*
//校验PIN码

VerifyPIN = (p_VerifyPIN)GetProcAddress(hinstLib, &quot;GS_VerifyPIN&quot;);
if(VerifyPIN == NULL)
{
printf(&quot;加载函数GS_VerifyPIN失败!/n&quot;);
return 0;
}
printf(&quot;加载函数GS_VerifyPIN成功!/n&quot;);
grv = (VerifyPIN)(&quot;1111&quot;);
if(grv!=GS_SUCCESS)
{
printf(&quot;校验PIN码失败!/n&quot;);
return 0;
}
printf(&quot;校验PIN码成功!/n&quot;);
//对数据进行签名
unsigned char signBuffer[128];
RSASign = (p_RSASign)GetProcAddress(hinstLib, &quot;GS_RSASign&quot;);
if(RSASign == NULL)
{
printf(&quot;加载函数GS_RSASign失败!/n&quot;);
return 0;
}
printf(&quot;加载函数GS_RSASign成功!/n&quot;);
grv = (RSASign)(plainBuffer1, signBuffer, 10);
if(grv != GS_SUCCESS)
{
printf(&quot;数据签名失败!/n&quot;);
return 0;
}
printf(&quot;数据签名成功!/n&quot;);
//获取公钥
unsigned char pukBuffer[128];
GetPublicKey = (p_GetPublicKey)GetProcAddress(hinstLib, &quot;GS_GetPublicKey&quot;);
if(GetPublicKey == NULL)
{
printf(&quot;加载函数GS_GetPublicKey失败!/n&quot;);
return 0;
}
printf(&quot;加载函数GS_GetPublicKeyy成功!/n&quot;);
brv = (GetPublicKey)(pukBuffer);
if(!brv)
{
printf(&quot;获取公钥失败!/n&quot;);
return 0;
}
printf(&quot;获取公钥成功!/n&quot;);
//验证数据签名
RSAVerify = (p_RSAVerify)GetProcAddress(hinstLib, &quot;GS_RSAVerify&quot;);
if(RSAVerify == NULL)
{
printf(&quot;加载函数GS_RSAVerify失败!/n&quot;);
return 0;
}
printf(&quot;加载函数GS_RSAVerify成功!/n&quot;);
grv = (RSAVerify)(signBuffer, plainBuffer1, pukBuffer, 10);
if(grv != GS_SUCCESS)
{
printf(&quot;数据签名错误!/n&quot;);
return 0;
}
printf(&quot;数据签名正确!/n&quot;);
*/
FreeLibrary(hinstLib);
return 0;
}
 
你可以找厂商要个Demo
 
你购买key的时候都会有相应的资料。现在你这样是问不出问题的。
厂家会给你demo,包括常用语言的,当然会有delphi,你看看就明白。
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部