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

📄 context.h

📁 基于SD卡的软实现CSP程序
💻 H
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
#ifndef INCL_CONTEXT_H
#define INCL_CONTEXT_H

#include <windows.h>
#include <wincrypt.h>
#include "HandleTable.h"
#include "RSAProvider.h"
#include "CRDSPEC_Card.h"
#include "PPManager.h"

#pragma once

class CContainer;

class CContext
{
public:
	CContext();
	~CContext();

	BOOL CContext::Initialize(const WCHAR IN * const pszContainer,const DWORD IN dwFlags, PVTableProvStruc IN pVTable);

	BOOL GetProvParam(DWORD dwParam, BYTE* pbData, DWORD* dwDataLen, DWORD dwFlags);
	BOOL SetProvParam(DWORD dwParam, BYTE* pbData, DWORD dwFlags);
	BOOL CreateHash(ALG_ID Algid, HCRYPTKEY hCryptKey, DWORD dwFlags, HCRYPTHASH* phHash);
	BOOL DestroyHash(HCRYPTHASH hHash);
	BOOL GetHashParam(HCRYPTHASH hHash, DWORD dwParam, BYTE* pbData, DWORD*pdwDataLen, DWORD dwFlags);
	BOOL HashData(HCRYPTHASH hHash, CONST BYTE* pbData, DWORD dwDatalen, DWORD dwFlags);
	BOOL HashSessionKey(HCRYPTHASH hHash, HCRYPTKEY hKey, DWORD dwFlags);
	BOOL SetHashParam(HCRYPTHASH hHash, DWORD dwParam, BYTE*pbData, DWORD dwFlags);
	BOOL Encrypt(HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final, DWORD dwFlags, BYTE* pbData, DWORD*pdwDataLen, DWORD dwBufLen);
	BOOL Decrypt(HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final, DWORD dwFlags, BYTE*pbData, DWORD*pdwDataLen);
	BOOL SignHash(HCRYPTHASH hHash, DWORD dwKeySpec, LPCWSTR sDescription, DWORD dwFlags, BYTE*pbSignature, DWORD* pdwSigLen);
	BOOL VerifySignature(HCRYPTHASH hHash, CONST BYTE* pbSignature, DWORD dwSigLen, HCRYPTKEY hPubKey, LPCWSTR sDescription, DWORD dwFlags);
	BOOL DeriveKey(ALG_ID Algid, HCRYPTHASH hBaseData, DWORD dwFlags, HCRYPTKEY* phKey);
	BOOL DestroyKey(HCRYPTKEY hKey);
	BOOL DuplicateKey(HCRYPTKEY hKey, DWORD* pdwReserved, DWORD dwFlags, HCRYPTKEY* phKey);
	BOOL ImportKey(BYTE* pbData, DWORD dwDataLen, HCRYPTKEY hPubKey, DWORD dwFlags, HCRYPTKEY* phKey);
	BOOL ExportKey(HCRYPTKEY hKey, HCRYPTKEY hPubKey, DWORD dwBlobType, DWORD dwFlags, BYTE* pbData, DWORD* pdwDataLen);
	BOOL GenKey(ALG_ID, DWORD dwFlags, HCRYPTKEY* phKey);
	BOOL GetKeyParam(HCRYPTKEY hKey, DWORD dwParam, BYTE* pbData, DWORD* pdwDataLen, DWORD dwFlags);
	BOOL SetKeyParam(HCRYPTKEY hKey, DWORD dwParam, BYTE*pbData, DWORD dwFlags);
	BOOL GetUserKey(DWORD dwKeySpec, HCRYPTKEY* phUserKey);
	BOOL GenRandom(DWORD dwLen, BYTE* pbBuffer);

	CContainer* GetCurrentContainer(){return m_pCurrentContainer;}
	DWORD GetFlags(){return m_dwFlags;}
	CCard* GetCard(){return &m_crd;}

	//Member function to verify if a ptr is a valid CContext
	static bool VerifyContext(CContext* pSpeculativeContext);

private:
	// The following 3 fields needed to get rid of generated private keys.
	static DWORD m_dwPrivKeySize; // Size of the prviate key to import
	static BYTE m_pbPrivKey[236]; // Actual Private Key Blob
	BOOL EraseKeyFromContainer( ALG_ID algid) ;
	typedef struct _tagSessionKeyHeader
	{
		BLOBHEADER blobHeader;
		ALG_ID algid;
	} SESSIONKEYHEADER, *LPSESSIONKEYHEADER;

	typedef struct _tagSessionKeyImportBlob
    {
        SESSIONKEYHEADER keyHeader;
        BYTE encryptedKey[0x80];    // size of the exponent-of-one keypair
    } SESSIONKEYIMPORTBLOB, *LPSESSIONKEYIMPORTBLOB;

	bool GetAsnLength(BYTE* pbyASNData, DWORD& dwLength);

	static CHandleTable m_sHT;
	DWORD m_dwFlags;
	CHandleTable m_htHash;
	CHandleTable m_htKey;
	CRSAProvider m_rsaProv;
	CCard m_crd;
	CContainer* m_pCurrentContainer;
	CPPManager m_ppManager;
};
#endif //INCL_CONTEXT_H

⌨️ 快捷键说明

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