⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pkcs11layer.cpp

📁 对PKCS11接口的封装
💻 CPP
字号:
/*===========================================================================


===========================================================================

		说明:

			通用函数 支持平台:WIN98/2K/XP...

		文件名:	

			Pkcs11Layer.cpp
---------------------------------------------------------------------------
		描述:		

			

---------------------------------------------------------------------------
		修改:

*===========================================================================*/

#include "stdafx.h"
#include "Pkcs11Layer.h"
#include "KeyCommon.h"
#include "KeyExport.h"

CPkcs11Layer::CPkcs11Layer(void)
{
	m_bTrue = TRUE;
	m_bFalse = FALSE;

	m_dwErrCode = CKR_OK; 
	m_hLibPkcs11 = NULL_PTR;
	m_Pkcs11FuncList = NULL_PTR;
	m_AuxPkcs11FuncList = NULL_PTR;

	LoadPkcs11Libary();
}

CPkcs11Layer::~CPkcs11Layer(void)
{
	DebugOutFunc("~CPkcs11Layer");

	FreePkcs11Libary();
	m_hLibPkcs11 = NULL_PTR;
	m_Pkcs11FuncList = NULL_PTR;
	m_AuxPkcs11FuncList = NULL_PTR;
}

//libary
long CPkcs11Layer::LoadPkcs11Libary()
{
	DebugOutFunc("LoadPkcs11Libary");
	
	m_dwErrCode = CKR_OK;
	
#ifdef	FTIAN_KEY	
	m_hLibPkcs11 = LoadLibrary("ngp11v211.dll");
#else
	m_hLibPkcs11 = LoadLibrary("zhtp11v211.dll");
#endif
	if(NULL_PTR == m_hLibPkcs11)
	{
		m_dwErrCode = USBKEY_INVALID_LIBRARY_PATH;
		DebugOutPosition(__FILE__, __LINE__);
		goto end;
	}
	
end:
	DebugOutRet(m_dwErrCode);
}

long CPkcs11Layer::FreePkcs11Libary()
{
	DebugOutFunc("FreePkcs11Libary");

	m_dwErrCode = CKR_OK;

	if(NULL_PTR != m_hLibPkcs11)
	{
		FreeLibrary(m_hLibPkcs11);
	}
	
	DebugOutRet(m_dwErrCode);
}

bool CPkcs11Layer::CheckPkcs11FuncList()
{
	if(NULL_PTR != m_Pkcs11FuncList && NULL_PTR != m_AuxPkcs11FuncList)
		return TRUE;
	else
	{
		C_GETFUNCTIONLISTPROC pC_GetFunctionList = NULL_PTR;

		pC_GetFunctionList = (C_GETFUNCTIONLISTPROC)GetProcAddress(m_hLibPkcs11, "C_GetFunctionList");
		if(pC_GetFunctionList == NULL_PTR)
		{
			m_dwErrCode = USBKEY_INVALID_LIBRARY_PATH;
			DebugOutPosition(__FILE__, __LINE__);
			goto end;
		}

		pE_GetAuxFunctionList = (EP_GetAuxFunctionList)GetProcAddress(m_hLibPkcs11, "E_GetAuxFunctionList");
		if(pE_GetAuxFunctionList == NULL_PTR)
		{
			m_dwErrCode = USBKEY_INVALID_LIBRARY_PATH;
			DebugOutPosition(__FILE__, __LINE__);
			goto end;
		}

		if(CKR_OK != pC_GetFunctionList(&m_Pkcs11FuncList))
		{
			m_dwErrCode = USBKEY_INVALID_LIBRARY_PATH;
			DebugOutPosition(__FILE__, __LINE__);
			goto end;
		}

		if(CKR_OK != pE_GetAuxFunctionList(&m_AuxPkcs11FuncList))
		{
			m_dwErrCode = USBKEY_INVALID_LIBRARY_PATH;
			DebugOutPosition(__FILE__, __LINE__);
			goto end;
		}

		if(NULL_PTR == m_Pkcs11FuncList || NULL_PTR == m_AuxPkcs11FuncList)
		{
			m_dwErrCode = USBKEY_INVALID_LIBRARY_PATH;
			DebugOutPosition(__FILE__, __LINE__);
			goto end;
		}

		m_dwErrCode = m_Pkcs11FuncList->C_Initialize(NULL_PTR);
		
		return TRUE;
	}
end:
	return FALSE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -