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

📄 protecteddata.h

📁 windows2000以上自带的加密api-dpapi的使用例子.
💻 H
字号:
//
// (w)ritten by andreas saurwein 2002, mailto:saurwein@uniwares.com
//
#pragma once
#include <wincrypt.h>
#pragma comment(lib, "Crypt32.lib")

#include <afxtempl.h>

class CProtectedData
{
public:
	CProtectedData(BOOL bSilent=TRUE, BOOL bLocal=FALSE, BOOL bAudit=FALSE);
	virtual ~CProtectedData(void);

	void SetUI(HWND hWnd, LPCTSTR pPrompt);
	void SetAudit(BOOL bAudit=TRUE);
	void SetLocal(BOOL bLocal=TRUE);

	void SetData(LPBYTE pData, DWORD dwSize);
	
	const DATA_BLOB* ProtectData();										// no description, no entropy
	const DATA_BLOB* ProtectData(LPCTSTR pDesc);						// no entropy
	const DATA_BLOB* ProtectData(LPCTSTR pDesc, const CString& rString);// entropy is a CString
	const DATA_BLOB* ProtectData(LPCTSTR pDesc, LPCTSTR pString);		// entropy is a LPCTSTR
	const DATA_BLOB* ProtectData(LPCTSTR pDesc, LPBYTE pEntropy, DWORD dwEntropySize);	// returns encrypted data and the size
	void FreeProtectedData();						// free the associated datablock

	DATA_BLOB* UnprotectData();											// no description, no entropy
	DATA_BLOB* UnprotectData(LPTSTR* pDesc);								// no entropy
	DATA_BLOB* UnprotectData(LPTSTR* pDesc, const CString& rString);		// entropy is a CString
	DATA_BLOB* UnprotectData(LPTSTR* pDesc, LPCTSTR pString);			// entropy is a LPCTSTR
	DATA_BLOB* UnprotectData(LPTSTR* pDesc, LPBYTE pEntropy, DWORD dwEntropySize);	// returns decrypted data and the size
	void FreeUnprotectedData();						// free the associated datablock

private:
	DATA_BLOB					m_ProtectedData;	// points to the protected data
	CRYPTPROTECT_PROMPTSTRUCT	m_Prompt;			// prompt data
	BOOL						m_bSilent;			// dont prompt
	BOOL						m_bLocal;			// use machine local encryption
	BOOL						m_bAudit;			// audit any encrypt/decrypt operation

	LPBYTE						m_pData;			// actual data
	DWORD						m_dwSize;			// actual size of data
};

class CUserProtectedData : public CProtectedData
{
public:
	CUserProtectedData(BOOL bSilent=TRUE, BOOL bAudit=FALSE) : CProtectedData(bSilent, FALSE, bAudit) {}
	virtual ~CUserProtectedData(void) {};
};

class CMachineProtectedData : public CProtectedData
{
public:
	CMachineProtectedData(BOOL bSilent=TRUE, BOOL bAudit=FALSE) : CProtectedData(bSilent, TRUE, bAudit) {}
	virtual ~CMachineProtectedData(void) {};
};

⌨️ 快捷键说明

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