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

📄 mainwin.cpp

📁 小型的局域网msg,免安装
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	msgMng->Send((ULONG)~0, htons(portNo), host_status, GetNickNameEx(), cfg->GroupNameStr);	// local network broadcast

	for (brobj=cfg->broadcastList.Top(); brobj; brobj=cfg->broadcastList.Next(brobj))
		BroadcastEntrySub(brobj->Addr(), htons(portNo), host_status);

	for (AddrObj *obj = (AddrObj *)cfg->DialUpList.TopObj(); obj != NULL; obj = (AddrObj *)cfg->DialUpList.NextObj(obj))
		BroadcastEntrySub(obj->addr, obj->portNo, host_status);

	if (mode == IPMSG_BR_ENTRY && cfg->ExtendEntry)
		::SetTimer(hWnd, IPMSG_ENTRY_TIMER, IPMSG_ENTRYMINSEC * 1000, NULL);
}

/*
	IPMSG_ENTRY/IPMSG_EXIT/IPMSG_ABSENCE僷働僢僩憲弌Sub
*/
void TMainWin::BroadcastEntrySub(ULONG addr, int port_no, ULONG mode)
{
	if (addr == 0)
		return;

	HostSub	hostSub;

	hostSub.addr 	= addr;
	hostSub.portNo	= port_no;

	BroadcastEntrySub(&hostSub, mode);
}

void TMainWin::BroadcastEntrySub(HostSub *hostSub, ULONG mode)
{
	if (mode == IPMSG_NOOPERATION)
		msgMng->Send(hostSub, mode);
	else
		msgMng->Send(hostSub, mode | (cfg->DialUpCheck ? IPMSG_DIALUPOPT : 0) | HostStatus(), GetNickNameEx(),  cfg->GroupNameStr);
}

/*
	icon 斀揮張棟丅startFlg == TRUE偺応崌丄媡icon偵 Reset偝傟傞
*/
void TMainWin::ReverseIcon(BOOL startFlg)
{
	static	cnt = 0;

	if (startFlg)
		cnt = 0;

	SetIcon(cnt++ % 2 ? hMainIcon : hRevIcon);
}

/*
	巜掕icon傪 MainWindow or TaskTray 偵僙僢僩
*/
void TMainWin::SetIcon(HICON hSetIcon)
{
	if (IsNewShell())
		TaskBar(NIM_MODIFY, hSetIcon);
	else {
		::SetClassLong(hWnd, GCL_HICON, (LONG)hSetIcon);
		::FlashWindow(hWnd, FALSE);
	}
}

/*
	HostList憲弌張棟
	庤敳偒 ... 僨儕儈僞傗僨乕僞偑側偄応崌偵摿庩暥帤('\a','\b')傪巊梡
*/
void TMainWin::SendHostList(MsgBuf *msg)
{
	int		start_no, len, total_len = 0, host_cnt = 0;
	char	*buf = new char [MAX_UDPBUF];
	char	tmp[MAX_BUF];

	if ((start_no = atoi(msg->msgBuf)) < 0)
		start_no = 0;

	total_len = wsprintf(buf, "%5d%c%5d%c", 0, HOSTLIST_SEPARATOR, 0, HOSTLIST_SEPARATOR);

	for (int cnt=start_no; cnt < hosts.HostCnt(); cnt++)
	{
		Host	*host = hosts.GetHost(cnt);
		if ((len = wsprintf(tmp, "%s%c%s%c%ld%c%s%c%d%c%s%c%s%c",
			host->hostSub.userName, HOSTLIST_SEPARATOR,
			host->hostSub.hostName, HOSTLIST_SEPARATOR,
			host->hostStatus, HOSTLIST_SEPARATOR,
			inet_ntoa(*(LPIN_ADDR)&host->hostSub.addr), HOSTLIST_SEPARATOR,
			host->hostSub.portNo, HOSTLIST_SEPARATOR,
			*host->nickName ? host->nickName : HOSTLIST_DUMMY, HOSTLIST_SEPARATOR,
			*host->groupName ? host->groupName : HOSTLIST_DUMMY, HOSTLIST_SEPARATOR
			)) + total_len +80 >= MAX_UDPBUF)	// +80 : ipmsg protocol header reserve
		{
			break;
		}
		memcpy(buf + total_len, tmp, len +1);
		total_len += len;
		host_cnt++;
	}
	len = wsprintf(tmp, "%5d%c%5d", start_no + host_cnt == hosts.HostCnt() ? 0 : start_no + host_cnt, HOSTLIST_SEPARATOR, host_cnt);
	memcpy(buf, tmp, len);
	msgMng->Send(&msg->hostSub, IPMSG_ANSLIST, buf);
	delete [] buf;
}

/*
	HostList庴怣張棟
*/
void TMainWin::AddHostList(MsgBuf *msg)
{
	char	*tok, *nickName, *groupName, *p;
	HostSub	hostSub;
	ULONG	host_status;
	int		total_num, continue_cnt;

	if ((tok = separate_token(msg->msgBuf, HOSTLIST_SEPARATOR, &p)) == NULL)
		return;
	continue_cnt = atoi(tok);

	if ((tok = separate_token(NULL, HOSTLIST_SEPARATOR, &p)) == NULL)
		return;
	total_num = atoi(tok);

	for (int host_cnt=0; (tok = separate_token(NULL, HOSTLIST_SEPARATOR, &p)) != NULL; host_cnt++)
	{
		nickName = groupName = NULL;
		strncpyz(hostSub.userName, tok, sizeof(hostSub.userName));

		if ((tok = separate_token(NULL, HOSTLIST_SEPARATOR, &p)) == NULL)
			break;
		strncpyz(hostSub.hostName, tok, sizeof(hostSub.hostName));

		if ((tok = separate_token(NULL, HOSTLIST_SEPARATOR, &p)) == NULL)
			break;
		host_status = GET_OPT(atol(tok));

		if ((tok = separate_token(NULL, HOSTLIST_SEPARATOR, &p)) == NULL)
			break;
		hostSub.addr = inet_addr(tok);

		if ((tok = separate_token(NULL, HOSTLIST_SEPARATOR, &p)) == NULL)
			break;
		hostSub.portNo = atoi(tok);

		if ((nickName = separate_token(NULL, HOSTLIST_SEPARATOR, &p)) == NULL)
			break;
		if (strcmp(nickName, HOSTLIST_DUMMY) == 0)
			nickName = "";

		if ((groupName = separate_token(NULL, HOSTLIST_SEPARATOR, &p)) == NULL)
			break;
		if (strcmp(groupName, HOSTLIST_DUMMY) == 0)
			groupName = "";

		AddHost(&hostSub, IPMSG_BR_ENTRY|host_status, nickName, groupName);
	}

	if (continue_cnt || host_cnt < total_num)
	{
		msgMng->Send(&msg->hostSub, IPMSG_GETLIST, abs(continue_cnt - (total_num - host_cnt)));
		if (::SetTimer(hWnd, IPMSG_LISTGETRETRY_TIMER, cfg->ListGetMSec, NULL))
			entryTimerStatus = IPMSG_LISTGETRETRY_TIMER;
	}
	else {
		entryStartTime = IPMSG_GETLIST_FINISH;
		if (cfg->ListGet)
			BroadcastEntry(IPMSG_BR_ENTRY);
	}
}

/*
	Log傪奐偔
*/
void TMainWin::LogOpen(void)
{
	SHELLEXECUTEINFO	shellExecInfo;

	memset(&shellExecInfo, 0, sizeof(shellExecInfo));
	shellExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
	shellExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
	shellExecInfo.hwnd = NULL;
	shellExecInfo.lpFile = cfg->LogFile;
	shellExecInfo.nShow = SW_SHOWNORMAL;

	if (!ShellExecuteEx(&shellExecInfo) || (int)shellExecInfo.hInstApp <= WINEXEC_ERR_MAX)
	{
		switch ((int)shellExecInfo.hInstApp)
		{
		case SE_ERR_NOASSOC: case SE_ERR_ASSOCINCOMPLETE:
			MessageBox(FILEEXTERR_MSGSTR);
			break;
		default:
			MessageBox(CANTOPENLOG_MSGSTR);
			break;
		}
	}
//	WaitForSingleObject(shellExecInfo.hProcess, INFINITE);
}

/*
	帺Host偺 Status (dialup mode / absence mode)
*/
ULONG TMainWin::HostStatus(void)
{
	return	(cfg->DialUpCheck ? IPMSG_DIALUPOPT : 0) | (cfg->AbsenceCheck ? IPMSG_ABSENCEOPT : 0) | (msgMng->IsAvailableTCP() ? IPMSG_FILEATTACHOPT : 0) | (cfg->pubKey.Key() || cfg->smallPubKey.Key() ? IPMSG_ENCRYPTOPT : 0);
}

/*
	IPMSG梡 icon弶婜壔
*/
void  TMainWin::InitIcon(void)
{
	if (*cfg->IconFile == 0 || (hMainIcon = ::ExtractIcon(TApp::hI, cfg->IconFile, 0)) == NULL)
		hMainIcon = ::LoadIcon(TApp::hI, (LPCSTR)IPMSG_ICON);
	if (*cfg->RevIconFile == 0 || (hRevIcon = ::ExtractIcon(TApp::hI, cfg->RevIconFile, 0)) == NULL)
		hRevIcon = ::LoadIcon(TApp::hI, (LPCSTR)RECV_ICON);
}

/*
	MainWindow icon傪嫵偊偰偁偘傞丅
	偙偺 routine偼 static member function 偱偁傝丄SendDlg側偳偐傜屇偽傟傞丅
*/
HICON TMainWin::GetIPMsgIcon(void)
{
	return	hMainIcon;
}

/*
	ListDlg 傪 Active or Hide偵乮扨側傞娙堈儖乕僠儞乯
*/
void TMainWin::ActiveListDlg(TList *list, BOOL active)
{
	for (TListDlg *dlg = (TListDlg *)list->TopObj(); dlg != NULL; dlg = (TListDlg *)list->NextObj(dlg))
		ActiveDlg(dlg, active);
}

/*
	ListDlg 傪 Delete 偡傞乮扨側傞娙堈儖乕僠儞乯
*/
void TMainWin::DeleteListDlg(TList *list)
{
	TListDlg *dlg;

	while ((dlg = (TListDlg *)list->TopObj()) != NULL)
	{
		list->DelObj(dlg);
		delete dlg;
	}
}

/*
	Dlg 傪 Active or Hide偵
*/
void TMainWin::ActiveDlg(TDlg *dlg, BOOL active)
{
	if (dlg->hWnd != 0)
		active ? dlg->Show(), dlg->SetForegroundWindow() : dlg->Show(SW_HIDE);
}

/*
	Extend NickName
*/
char *TMainWin::GetNickNameEx(void)
{
	static char buf[MAX_LISTBUF];

	if (cfg->AbsenceCheck && *cfg->AbsenceHead[cfg->AbsenceChoice])
		wsprintf(buf, "%s[%s]", *cfg->NickNameStr ? cfg->NickNameStr : msgMng->GetLocalHost()->userName, cfg->AbsenceHead[cfg->AbsenceChoice]);
	else
		strcpy(buf, *cfg->NickNameStr ? cfg->NickNameStr : msgMng->GetLocalHost()->userName);

	return	buf;
}

/* VC4 偱 CryptoAPI 傪巊梡壜擻偵偡傞 */
BOOL (WINAPI *pCryptAcquireContext)(HCRYPTPROV *, LPCSTR, LPCSTR, DWORD, DWORD);
BOOL (WINAPI *pCryptDestroyKey)(HCRYPTKEY);
BOOL (WINAPI *pCryptGetKeyParam)(HCRYPTKEY, DWORD, BYTE *, DWORD *, DWORD);
BOOL (WINAPI *pCryptSetKeyParam)(HCRYPTKEY, DWORD, BYTE *, DWORD);
BOOL (WINAPI *pCryptExportKey)(HCRYPTKEY, HCRYPTKEY, DWORD, DWORD, BYTE *, DWORD *);
BOOL (WINAPI *pCryptGetUserKey)(HCRYPTPROV, DWORD, HCRYPTKEY *);
BOOL (WINAPI *pCryptEncrypt)(HCRYPTKEY, HCRYPTHASH, BOOL, DWORD, BYTE *, DWORD *, DWORD);
BOOL (WINAPI *pCryptGenKey)(HCRYPTPROV, ALG_ID, DWORD, HCRYPTKEY *);
BOOL (WINAPI *pCryptGenRandom)(HCRYPTPROV, DWORD, BYTE *);
BOOL (WINAPI *pCryptImportKey)(HCRYPTPROV, CONST BYTE *, DWORD, HCRYPTKEY, DWORD, HCRYPTKEY *);
BOOL (WINAPI *pCryptDecrypt)(HCRYPTKEY, HCRYPTHASH, BOOL, DWORD, BYTE *, DWORD *);
BOOL (WINAPI *pCryptReleaseContext)(HCRYPTPROV, DWORD);

BOOL (WINAPI *pCryptCreateHash)(HCRYPTPROV, ALG_ID, HCRYPTKEY, DWORD, HCRYPTHASH *);
BOOL (WINAPI *pCryptHashData)(HCRYPTHASH, BYTE *, DWORD, DWORD);
BOOL (WINAPI *pCryptSignHash)(HCRYPTHASH, DWORD, LPCSTR, DWORD, BYTE *, DWORD *);
BOOL (WINAPI *pCryptVerifySignature)(HCRYPTHASH, CONST BYTE *, DWORD, HCRYPTKEY, LPCSTR, DWORD);
BOOL (WINAPI *pCryptProtectData)(DATA_BLOB* pDataIn, LPCWSTR szDataDescr, DATA_BLOB* pOptionalEntropy, PVOID pvReserved, CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct, DWORD dwFlags, DATA_BLOB* pDataOut);
BOOL (WINAPI *pCryptUnprotectData)(DATA_BLOB* pDataIn, LPWSTR* ppszDataDescr, DATA_BLOB* pOptionalEntropy, PVOID pvReserved, CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct, DWORD dwFlags, DATA_BLOB* pDataOut);


BOOL TMainWin::SetupCryptAPI(void)
{
	HINSTANCE	advdll;

	cfg->hCsp = cfg->hSmallCsp = NULL;

	if ((advdll = ::LoadLibrary("advapi32.dll")) == NULL)
		return	GetLastErrorMsg("advapi32"), FALSE;

	pCryptAcquireContext = (BOOL (WINAPI *)(HCRYPTPROV *, LPCSTR, LPCSTR, DWORD, DWORD))::GetProcAddress(advdll, "CryptAcquireContextA");
	pCryptDestroyKey = (BOOL (WINAPI *)(HCRYPTKEY))::GetProcAddress(advdll, "CryptDestroyKey");
	pCryptGetKeyParam = (BOOL (WINAPI *)(HCRYPTKEY, DWORD, BYTE *, DWORD *, DWORD))::GetProcAddress(advdll, "CryptGetKeyParam");
	pCryptSetKeyParam = (BOOL (WINAPI *)(HCRYPTKEY, DWORD, BYTE *, DWORD))::GetProcAddress(advdll, "CryptSetKeyParam");
	pCryptExportKey = (BOOL (WINAPI *)(HCRYPTKEY, HCRYPTKEY, DWORD, DWORD, BYTE *, DWORD *))::GetProcAddress(advdll, "CryptExportKey");
	pCryptGetUserKey = (BOOL (WINAPI *)(HCRYPTPROV, DWORD, HCRYPTKEY *))::GetProcAddress(advdll, "CryptGetUserKey");
	pCryptEncrypt = (BOOL (WINAPI *)(HCRYPTKEY, HCRYPTHASH, BOOL, DWORD, BYTE *, DWORD *, DWORD))::GetProcAddress(advdll, "CryptEncrypt");
	pCryptGenKey = (BOOL (WINAPI *)(HCRYPTPROV, ALG_ID, DWORD, HCRYPTKEY *))::GetProcAddress(advdll, "CryptGenKey");
	pCryptGenRandom = (BOOL (WINAPI *)(HCRYPTPROV, DWORD, BYTE *))::GetProcAddress(advdll, "CryptGenRandom");
	pCryptImportKey = (BOOL (WINAPI *)(HCRYPTPROV, CONST BYTE *, DWORD, HCRYPTKEY, DWORD, HCRYPTKEY *))::GetProcAddress(advdll, "CryptImportKey");
	pCryptDecrypt = (BOOL (WINAPI *)(HCRYPTKEY, HCRYPTHASH, BOOL, DWORD, BYTE *, DWORD *))::GetProcAddress(advdll, "CryptDecrypt");
	pCryptCreateHash = (BOOL (WINAPI *)(HCRYPTPROV, ALG_ID, HCRYPTKEY, DWORD, HCRYPTHASH *))::GetProcAddress(advdll, "CryptCreateHash");
	pCryptHashData = (BOOL (WINAPI *)(HCRYPTHASH, BYTE *, DWORD, DWORD))::GetProcAddress(advdll, "CryptHashData");
	pCryptSignHash = (BOOL (WINAPI *)(HCRYPTHASH, DWORD, LPCSTR, DWORD, BYTE *, DWORD *))::GetProcAddress(advdll, "CryptSignHashA");
	pCryptVerifySignature = (BOOL (WINAPI *)(HCRYPTHASH, CONST BYTE *, DWORD, HCRYPTKEY, LPCSTR, DWORD))::GetProcAddress(advdll, "CryptVerifySignatureA");
	pCryptReleaseContext = (BOOL (WINAPI *)(HCRYPTPROV, DWORD))::GetProcAddress(advdll, "CryptReleaseContext");

	HINSTANCE	cryptdll;
	if (cryptdll = ::LoadLibrary("crypt32.dll"))
	{
		pCryptProtectData = (BOOL (WINAPI *)(DATA_BLOB* pDataIn, LPCWSTR szDataDescr, DATA_BLOB* pOptionalEntropy, PVOID pvReserved, CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct, DWORD dwFlags, DATA_BLOB* pDataOut))::GetProcAddress(cryptdll, "CryptProtectData");
		pCryptUnprotectData = (BOOL (WINAPI *)(DATA_BLOB* pDataIn, LPWSTR* ppszDataDescr, DATA_BLOB* pOptionalEntropy, PVOID pvReserved, CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct, DWORD dwFlags, DATA_BLOB* pDataOut))::GetProcAddress(cryptdll, "CryptUnprotectData");
	}
	if (pCryptProtectData == NULL && cfg->privEncryptType == PRIV_BLOB_DPAPI)
		cfg->privEncryptType = PRIV_BLOB_RAW;

	if (pCryptAcquireContext == NULL)
		return	GetLastErrorMsg("CryptAcquireContext"), FALSE;

	SetupCryptAPICore();

// 婲摦捈屻偵丄傑傟偵僐働傞娐嫬偑偁傞傜偟偄偺偱丄傢偢偐偵儕僩儔僀...
#define MAX_RETRY	3
	int	cnt = 0;
	while (cfg->hCsp && cfg->pubKey.Key() == NULL || cfg->hSmallCsp && cfg->smallPubKey.Key() == NULL)
	{
		if (++cnt > MAX_RETRY)
			break;
		if (cfg->hCsp)
			pCryptReleaseContext(cfg->hCsp, 0), cfg->hCsp = NULL;
		if (cfg->hSmallCsp)
			pCryptReleaseContext(cfg->hSmallCsp, 0), cfg->hSmallCsp = NULL;
		::Sleep(1000);
		SetupCryptAPICore(cnt == MAX_RETRY ? KEY_DIAG : 0);
	}
	if (cnt > MAX_RETRY || cfg->pubKey.Key() == NULL && cfg->smallPubKey.Key() == NULL)
	{
		if (MessageBox("RSA failed. Create New RSA key?", "msg", MB_OKCANCEL) == IDOK)
			SetupCryptAPICore(KEY_REBUILD|KEY_DIAG);
	}

#if 0
	if (cfg->pubKey.Key())
	{
		char	hash[MAX_NAMEBUF];
		MakeHash(cfg->pubKey.Key(), cfg->pubKey.KeyLen(), hash);
		int	len = strlen(msgMng->GetLocalHost()->userName);
		wsprintf(msgMng->GetLocalHost()->userName + min(len, 32), "@%s", hash);
	}
#endif

	return	cfg->pubKey.Key() || cfg->smallPubKey.Key();
}

BOOL TMainWin::SetupCryptAPICore(int ctl_flg)
{
	BYTE	data[MAX_BUF];
	int		len = sizeof(data);

// RSA 尞偺惗惉
	SetupRSAKey(1024, ctl_flg);
	SetupRSAKey(512, ctl_flg);

// Self Check 1024bit
	if (cfg->pubKey.Key()) {
		BOOL		ret = FALSE;
		HCRYPTKEY	hExKey = 0;

		cfg->pubKey.KeyBlob(data, sizeof(data), &len);
		if (pCryptImportKey(cfg->hCsp, data, len, 0, 0, &hExKey)) {
			len = 128/8;
			if (pCryptEncrypt(hExKey, 0, TRUE, 0, data, (DWORD *)&len, MAX_BUF))
				ret = TRUE;
			else if (ctl_flg & KEY_DIAG) GetLastErrorMsg("CryptEncrypt test1024");
			pCryptDestroyKey(hExKey);
		}
		else if (ctl_flg & KEY_DIAG) GetLastErrorMsg("CryptImportKey test1024");

		if (ret) {
			ret = FALSE;
			if (pCryptDecrypt(cfg->hPrivKey, 0, TRUE, 0, (BYTE *)data, (DWORD *)&len))
				ret = TRUE;
			else if (ctl_flg & KEY_DIAG) GetLastErrorMsg("CryptDecrypt test1024");
		}

		if (ret == FALSE)
			cfg->pubKey.UnSet();
	}

// Self Check 512bit
	if (cfg->smallPubKey.Key()) {
		BOOL		ret = FALSE;
		BYTE		tmp[MAX_BUF];
		DWORD		tmplen = MAX_BUF / 2;
		HCRYPTKEY	hKey = 0, hExKey = 0;

		cfg->smallPubKey.KeyBlob(data, sizeof(data), &len);
		if (pCryptImportKey(cfg->hSmallCsp, data, len, 0, 0, &hExKey)) {
			if (pCryptGenKey(cfg->hSmallCsp, CALG_RC2, CRYPT_EXPORTABLE, &hKey)) {
				pCryptExportKey(hKey, hExKey, SIMPLEBLOB, 0, NULL, (DWORD *)&len);
				if (pCryptExportKey(hKey, hExKey, SIMPLEBLOB, 0, data, (DWORD *)&len)) {
					if (pCryptEncrypt(hKey, 0, TRUE, 0, tmp, &tmplen, MAX_BUF))
						ret = TRUE;
					else if (ctl_flg & KEY_DIAG) GetLastErrorMsg("CryptEncrypt test512");
				}
				else if (ctl_flg & KEY_DIAG) GetLastErrorMsg("CryptExportKey test512");
				pCryptDestroyKey(hKey);
			}
			else if (ctl_flg & KEY_DIAG) GetLastErrorMsg("CryptGenKey test512");
			pCryptDestroyKey(hExKey);
		}
		else if (ctl_flg & KEY_DIAG) GetLastErrorMsg("CryptImportKey test512");

		if (ret) {
			ret = FALSE;
			if (pCryptImportKey(cfg->hSmallCsp, data, len, cfg->hSmallPrivKey, 0, &hKey)) {
				if (pCryptDecrypt(hKey, 0, TRUE, 0, (BYTE *)tmp, (DWORD *)&tmplen))
					ret = TRUE;
				else if (ctl_flg & KEY_DIAG) GetLastErrorMsg("CryptDecrypt test512");
				pCryptDestroyKey(hKey);
			}
			else if (ctl_flg & KEY_DIAG) GetLastErrorMsg("CryptImportKey test512");
		}

		if (ret == FALSE)
			cfg->smallPubKey.UnSet();
	}

	if (cfg->pubKey.Key() == NULL && cfg->hPrivKey)
		pCryptDestroyKey(cfg->hPrivKey), cfg->hPrivKey = NULL;
	if (cfg->smallPubKey.Key() == NULL && cfg->hSmallPrivKey)
		pCryptDestroyKey(cfg->hSmallPrivKey), cfg->hSmallPrivKey = NULL;

	return	cfg->pubKey.Key() || cfg->smallPubKey.Key();
}

BOOL TMainWin::SetupRSAKey(int bitLen, int ctl_flg)
{
	BOOL		isSmall = bitLen == 512 ? TRUE : FALSE;
	BYTE		data[MAX_BUF];
	char		*contName = (char *)data;
	int			len = sizeof(data);
	HCRYPTPROV&	hCsp = isSmall ? cfg->hSmallCsp : cfg->hCsp;
	HCRYPTKEY&	hPrivKey = isSmall ? cfg->hSmallPrivKey : cfg->hPrivKey;
	PubKey&		pubKey = isSmall ? cfg->smallPubKey : cfg->pubKey;
	const char	*csp_name = isSmall ? MS_DEF_PROV : MS_ENHANCED_PROV;

	int	cap = isSmall ? IPMSG_RSA_512|IPMSG_RC2_40 : IPMSG_RSA_1024|IPMSG_BLOWFISH_128;
	int	SmallAcqFlags[] = { CRYPT_MACHINE_KEYSET, 0, CRYPT_NEWKEYSET|CRYPT_MACHINE_KEYSET, CRYPT_NEWKEYSET, -1 };
	int	BigAcqFlags[] = { CRYPT_MACHINE_KEYSET, CRYPT_NEWKEYSET|CRYPT_MACHINE_KEYSET, -1 };
	int	*AcqFlgs = isSmall ? SmallAcqFlags : BigAcqFlags;

	wsprintf(contName, "ipmsg.rsa%d.%s", bitLen, msgMng->GetLocalHost()->userName);

// rebuld 帪偵偼丄帠慜偵岞奐尞傪徚嫀
	if ((ctl_flg & KEY_REBUILD) && hCsp && pubKey.Key() == NULL)
	{
		pCryptReleaseContext(hCsp, 0), hCsp = NULL;
		if (!pCryptAcquireContext(&hCs

⌨️ 快捷键说明

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