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

📄 cryptoencryptiondlg.h

📁 一种使用动态公匙加密方式的加密算法
💻 H
字号:
// CryptoEncryptionDlg.h : header file
//

#if !defined(AFX_CRYPTOENCRYPTIONDLG_H__607FC8FD_25A3_4C5D_B3A4_C703A3D99358__INCLUDED_)
#define AFX_CRYPTOENCRYPTIONDLG_H__607FC8FD_25A3_4C5D_B3A4_C703A3D99358__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <wincrypt.h>

extern const char KEY_FILE[255];

/////////////////////////////////////////////////////////////////////////////
// CCryptoEncryptionDlg dialog

class CCryptoEncryptionDlg : public CDialog
{
// Construction
public:
	CCryptoEncryptionDlg(CWnd* pParent = NULL);	// standard constructor

	~CCryptoEncryptionDlg()
	{

		if (!CryptExportKey(hSessionKey, hKey, SIMPLEBLOB, 0, NULL, &cbBlob))
		{
			dwResult = GetLastError();
			MessageBox("Error CryptExportKey() failed.", "Information", MB_OK);
			return;
		}
		if (!CryptExportKey(hSessionKey, hKey, SIMPLEBLOB, 0, NULL, &cbBlob))
		{
			dwResult = GetLastError();
			MessageBox("Error CryptExportKey() failed.", "Information", MB_OK);
			return;
		}
		if ((pbBlob = (BYTE *) LocalAlloc(LMEM_ZEROINIT,cbBlob)) == NULL)
		{
			dwResult = ERROR_NOT_ENOUGH_MEMORY;
			MessageBox("Error LocalAlloc() failed.", "Information", MB_OK);
			return;
		}
		if (!CryptExportKey(hSessionKey, hKey, SIMPLEBLOB, 0, pbBlob, &cbBlob))
		{
			dwResult = GetLastError();
			MessageBox("Error CryptExportKey() failed.", "Information", MB_OK);
			return;
		}

		if(hSessionKey != 0) 
			CryptDestroyKey(hSessionKey);

		hSessionKey = 0;

		FILE *fp = fopen(KEY_FILE, "w+b");
		if (fp) {
			fwrite(pbBlob, 1, cbBlob, fp);
			fclose(fp);
		}

		if (pbBlob)
			LocalFree(pbBlob);

		if(hKey != 0) CryptDestroyKey(hKey);
		if(hProv != 0) CryptReleaseContext(hProv, 0);
	}

// Dialog Data
	//{{AFX_DATA(CCryptoEncryptionDlg)
	enum { IDD = IDD_CRYPTOENCRYPTION_DIALOG };
	CString	m_cipher;
	CString	m_clear;
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CCryptoEncryptionDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	//{{AFX_MSG(CCryptoEncryptionDlg)
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg void OnButtonEncrypt();
	afx_msg void OnButtonDecrypt();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()

private:
	DWORD dwResult;
	HCRYPTPROV hProv;
	HCRYPTKEY hKey;
	HCRYPTKEY hSessionKey;
	DWORD cbBlob;
	BYTE *pbBlob;
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_CRYPTOENCRYPTIONDLG_H__607FC8FD_25A3_4C5D_B3A4_C703A3D99358__INCLUDED_)

⌨️ 快捷键说明

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