资源简介
PKCS11读取UKEY例子,学习PKCS11最好的代码
代码片段和文件信息
//*****************************************************************************
//
// ASYMKEYCIPHERFUNCTIONS.C
// Version 3.0
// 04.29.02
//
// CLAIM:
// This sample code is used for the purpose of the
// company‘s internal training and guidance only. DigiCrypto will not
// be responsible for the use of this code for any purpose other than
// what described above.
//
//*****************************************************************************
//
// Purpose:
// This sample ‘C‘ code is in accordance with the PKCS-11 version 2.10
// and included the following PKCS11 functions:
// C_EncryptInit
// C_Encrypt
// C_DecryptInit
// C_Decrypt
//
//*****************************************************************************
#include
#include
#include
#include
#pragma pack(push cryptoki 1)
#include “pkcs11.h“
#pragma pack(pop cryptoki)
char ProjName[] = “AsymKeyCipherFunctions Project“;
#include “globals.h“
void main ()
{
CK_RV rv;
CK_SLOT_ID_PTR pSlotList;
CK_SLOT_ID slotID;
CK_ULONG slotCount;
CK_SESSION_HANDLE hSession;
CK_object_HANDLE hPrivKey hPubKey;
CK_ULONG pubCount privCount;
CK_ULONG ulDataLen;
CK_BYTE_PTR pPlainText;
CK_BYTE_PTR pEncryptedData;
CK_ULONG ulPlainTextLen ulEncryptedDataLen;
int i;
//CK_BYTE Data[10] = {1 2 3 4 5 6 7 8 9 10};
/*
CK_BYTE Data[80] = {
1 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 10
};*/
CK_MECHANISM mechGenRSA = { CKM_RSA_PKCS_KEY_PAIR_GEN NULL_PTR 0 };
CK_MECHANISM mechRSA = { CKM_RSA_PKCS NULL_PTR 0 };
CK_MECHANISM mechRSAX509 = { CKM_RSA_X_509 NULL_PTR 0 };
CK_ULONG modulusBits = 1024;
CK_BYTE publicExponent[] = {101};
CK_BYTE id[] = {123};
CK_BBOOL True = TRUE;
CK_ATTRIBUTE publicKeyTemplate[] = {
{CKA_ENCRYPT &True sizeof(True)}
{CKA_VERIFY &True sizeof(True)}
{CKA_MODULUS_BITS &modulusBits sizeof(modulusBits)}
{CKA_PUBLIC_EXPONENT publicExponent sizeof (publicExponent)}
};
CK_ATTRIBUTE privateKeyTemplate[] = {
{CKA_TOKEN &True sizeof(True)}
{CKA_PRIVATE &True sizeof(True)}
{CKA_ID id sizeof(id)}
{CKA_SENSITIVE &True sizeof(True)}
{CKA_DECRYPT &True sizeof(True)}
{CKA_SIGN &True sizeof(True)}
};
CK_BYTE* Data=NULL;
ulDataLen = 2;
Data = (CK_BYTE_PTR)malloc(ulDataLen);
for(i=1;i<=ulDataLen;i++){
Data[i-1] = i;
}
GetLocalTime(&st);
TESTINITIALIZE; //Macro defined in the “globals.h“. This is not
//PKCS-11 code. It‘s used in this workspace only.
rv = C_Initialize (NULL_PTR);
if (rv != CKR_OK) {
fprintf(STDERR“***** C_Initialize fails. Error Code: 0x%08x Line %d\n“ rv __LINE__);
exit(1); //can not do anything quit
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 15038 2008-05-30 08:38 PKCS11_Sample\AsymKeyCipherFunctions\AsymKeyCipherFunctions.c
文件 4329 2009-12-08 16:19 PKCS11_Sample\AsymKeyCipherFunctions\AsymKeyCipherFunctions.dsp
文件 45056 2008-05-30 08:38 PKCS11_Sample\bin\Release\WDPKCS.dll
文件 4933 2008-05-30 08:38 PKCS11_Sample\CardFormatter\CardFormatter.c
文件 4195 2009-12-08 16:19 PKCS11_Sample\CardFormatter\CardFormatter.dsp
文件 12174 2008-05-30 08:38 PKCS11_Sample\CreateDeleteob
文件 4412 2009-12-08 16:19 PKCS11_Sample\CreateDeleteob
文件 5663 2008-05-30 08:38 PKCS11_Sample\DCP11Sample.dsw
文件 3824 2008-05-30 08:38 PKCS11_Sample\GenPurposeFunctions\GenPurposeFunctions.c
文件 4280 2009-12-08 16:19 PKCS11_Sample\GenPurposeFunctions\GenPurposeFunctions.dsp
文件 1996 2008-05-30 08:38 PKCS11_Sample\include\globals.h
文件 8828 2008-05-30 08:38 PKCS11_Sample\include\PKCS11.H
文件 28504 2008-05-30 08:38 PKCS11_Sample\include\PKCS11F.H
文件 46316 2008-05-30 08:38 PKCS11_Sample\include\PKCS11T.H
文件 15572 2008-05-30 08:38 PKCS11_Sample\include\WDPKCS_311.lib
文件 15892 2008-05-30 08:38 PKCS11_Sample\KeyExchangeFunctions\KeyExchangeFunctions.c
文件 4299 2009-12-08 16:19 PKCS11_Sample\KeyExchangeFunctions\KeyExchangeFunctions.dsp
文件 9855 2008-05-30 08:38 PKCS11_Sample\KeyGenFunctions\KeyGenFunctions.c
文件 4272 2009-12-08 16:19 PKCS11_Sample\KeyGenFunctions\KeyGenFunctions.dsp
文件 9886 2008-05-30 08:38 PKCS11_Sample\MessageDigestFunctions\MessageDigestFunctions.c
文件 4370 2009-12-08 16:19 PKCS11_Sample\MessageDigestFunctions\MessageDigestFunctions.dsp
文件 14849 2008-05-30 08:38 PKCS11_Sample\ob
文件 4417 2009-12-08 16:19 PKCS11_Sample\ob
文件 5249 2008-05-30 08:38 PKCS11_Sample\RandomGenerationFunctions\RandomGenerationFunctions.c
文件 4374 2009-12-08 16:19 PKCS11_Sample\RandomGenerationFunctions\RandomGenerationFunctions.dsp
文件 573 2008-05-30 08:38 PKCS11_Sample\RandomGenerationFunctions\RandomGenerationFunctions.dsw
文件 15834 2008-05-30 08:38 PKCS11_Sample\Searchob
文件 4356 2009-12-08 16:19 PKCS11_Sample\Searchob
文件 6957 2008-05-30 08:38 PKCS11_Sample\SessionManagementFunctions\SessionManagementFunctions.c
文件 4385 2009-12-08 16:19 PKCS11_Sample\SessionManagementFunctions\SessionManagementFunctions.dsp
............此处省略32个文件信息
评论
共有 条评论