62,073
社区成员
发帖
与我相关
我的任务
分享
/******************************************************************
** 版 权: (C)
** 文件名: IEncryptDll.h
** 创建人:
** 日 期: 2014-4-18
** 版 本: 0.1
** 描 述: 账号密码加密
** 应 用:
**************************** 修改记录 ******************************
** 修改人:
** 日 期:
** 描 述:
********************************************************************/
#ifndef _IENCRYPTDLL_H_
#define _IENCRYPTDLL_H_
#define MD5_MAXLEN 33
class IEncryptModule
{
public:
//这个就是C++的头文件
// 释放
virtual void Release() = NULL;
// 输入玩家密码,返回第一阶段密码
virtual char* GetFPhaseViaPassword(const char* pPassword, char* pFPhase, unsigned int nFPhaseLength) = NULL;
// 输入第一阶段,返回第三阶段密码
virtual char* GetTPhaseViaFPhase(char* pFPhase) = NULL;
// 输入玩家密码,返回第三阶段密码
virtual char* GetTPhaseViaPassword(const char* pPassword, char* pTPhase, unsigned int nTPhaseLength) = NULL;
};
// 账号密码加密HELPER类
class CEncryptModuleHelper
{
private:
HINSTANCE m_hdll;
char m_szErrMsg[128]; //错误信息
public:
IEncryptModule *m_pEncryptModule;
// 创建类工厂
typedef BOOL (*ProcCreateEncryptModule)(IEncryptModule **ppSystem);
CEncryptModuleHelper() : m_hdll(NULL), m_pEncryptModule(NULL)
{
memset(m_szErrMsg, 0, sizeof(m_szErrMsg));
}
~CEncryptModuleHelper()
{
Close();
}
IEncryptModule* operator ->()
{
return m_pEncryptModule;
}
void Close()
{
if (NULL != m_pEncryptModule)
{
//delete m_pEncryptModule;
m_pEncryptModule->Release();
m_pEncryptModule = NULL;
}
if (NULL != m_hdll)
{
FreeLibrary(m_hdll);
m_hdll = NULL;
}
}
BOOL Create()
{
Close();
try
{
if ( !LoadDll() )
{
return FALSE;
}
ProcCreateEncryptModule proc;
proc = (ProcCreateEncryptModule) GetProcAddress(m_hdll, "CreateEncryptModule");
if (NULL == proc)
{
throw "Can't GetProcAddress('CreateEncryptModule')";
}
if ( !proc(&m_pEncryptModule) )
{
throw "CreateEncryptModule() error!";
}
}
catch (LPCSTR szMsg)
{
lstrcpyn(m_szErrMsg, szMsg, sizeof(m_szErrMsg));
return FALSE;
}
catch(...)
{
lstrcpyn(m_szErrMsg, "Unknown Error!", sizeof(m_szErrMsg));
return FALSE;
}
return TRUE;
}
BOOL LoadDll()
{
if (NULL == m_hdll)
{
m_hdll = LoadLibrary( "EncryptDll.dll" );
if(NULL == m_hdll)
throw "Can't load EncryptDll.dll";
return TRUE;
}
return FALSE;
}
//判断接口指针是否有效
BOOL IsValid()
{
return (NULL != m_pEncryptModule);
}
char* GetErrMsg()
{
return m_szErrMsg;
}
IEncryptModule* GetEncryptModule()
{
return m_pEncryptModule;
}
};
#endif /* _IENCRYPTDLL_H_ */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace Bll
{
unsafe public abstract class IEncryptModule
{
public abstract void Release();
public abstract unsafe char* GetFPhaseViaPassword(char* pPassword, char* pFPhase, uint nFPhaseLength);
public abstract unsafe char* GetTPhaseViaFPhase(char* pFPhase);
public abstract unsafe char* GetTPhaseViaPassword(char* pPassword, char* pTPhase, uint nTPhaseLength);
}
unsafe class CEncryptModuleHelper
{
[DllImport("EncryptDll.dll")]
public static extern unsafe bool CreateEncryptModule(IEncryptModule **ppSystem);
public unsafe IEncryptModule *m_pEncryptModule;
public bool CreateEncryptModulebool()
{
return CreateEncryptModule(&m_pEncryptModule);
}
public unsafe char* passwordmw(char* pPassword, char* pTPhase, uint nTPhaseLength)
{
if (CreateEncryptModulebool())
{
return m_pEncryptModule->GetTPhaseViaPassword(pPassword, pTPhase, nTPhaseLength);
}
}
}
}