📄 crdspec_container.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_CRDSPEC_CONTAINER_H
#define INCL_CRDSPEC_CONTAINER_H
#include <windows.h>
#include <wincrypt.h>
#include "HandleTable.h"
#include "cspconst.h"
#include "csp.h"
#pragma once
#include "CRDSPEC_Card.h"
typedef PCCERT_CONTEXT (WINAPI *CERTCREATECERTIFICATECONTEXT)(
DWORD dwCertEncodingType,
const BYTE *pbCertEncoded,
DWORD cbCertEncoded
);
typedef BOOL ( WINAPI *CRYPTIMPORTPUBLICKEYINFOEX)(
IN HCRYPTPROV hCryptProv,
IN DWORD dwCertEncodingType,
IN PCERT_PUBLIC_KEY_INFO pInfo,
IN ALG_ID aiKeyAlg,
IN DWORD dwFlags,
IN OPTIONAL void *pvAuxInfo,
OUT HCRYPTKEY *phKey
);
typedef BOOL (WINAPI *CERTFREECERTIFICATECONTEXT)(
PCCERT_CONTEXT pCertContext
);
class CContainer
{
public:
CContainer();
~CContainer();
bool CContainer::Initialize(CCard* pCrd, int iSerNum, PBYTE pbContainerFile, int cbContainerFile);
const WCHAR * const GetName(){return &m_pszName[0];}
int GetSerNum() {return m_iSerNum;}
bool Delete();
bool Decrypt(ALG_ID algid, BYTE* pbySource, DWORD wSourceLength, BYTE* pbyDestination, DWORD* pwDestinationLen);
bool GetPublicKey(HCRYPTPROV hProv, ALG_ID algid, HCRYPTKEY* phKey);
bool GetPublicKeyFromCert(HCRYPTPROV hProv, ALG_ID algid, HCRYPTKEY* phKey,BYTE *pbyCertFile,DWORD cbCertLen);
bool GetCertificate(ALG_ID algid, BYTE* pbyBuffer, DWORD *pdwBuffLen);
bool SetCertificate(ALG_ID algid, BYTE* pbyBuffer, DWORD dwBuffLen);
bool GetKeyInfoOfKey(ALG_ID algid, CCard::KEYINFO *kiFileID);
int GetNumKeys(){return m_iNumKeys;}
CCard::KEYINFO * NewKey(CCard::KEYINFO *pKeyInfo);
void IncNumKeys(){m_iNumKeys++;}
int GetNextKeyNum(){return m_iNextKeyNum++;}
bool SetCachedCert(ALG_ID algid, BYTE* pbyBuffer, DWORD dwBuffLen);
private:
bool LoadCAPI2Lib();
PBYTE GetCachedCert(ALG_ID algid, DWORD *len);
DWORD RemapAlgIdToCacheIndex(ALG_ID a);
int m_iSerNum;
WCHAR* m_pszName;
CCard* m_pCard;
int m_iNextKeyNum;
int m_iNumKeys;
CCard::KEYINFO *m_pKeyInfo;
// Our local cache of the .crt File
//
PBYTE m_pCertFile[2];
DWORD m_dwCertLen[2];
HMODULE m_hCAPI2Lib;
CRYPTIMPORTPUBLICKEYINFOEX m_lpfnImportPublicKeyInfoEx;
CERTCREATECERTIFICATECONTEXT m_lpfnCreateCertificateContext;
CERTFREECERTIFICATECONTEXT m_lpfnFreeCertificateContext;
CSPFile fp;
};
#endif//INCL_CRDSPEC_CONTAINER_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -