00001
00009 #ifndef __PKIFCNGCAPI_H__
00010 #define __PKIFCNGCAPI_H__
00011
00012 #include "PKIFdll.h"
00013 #include "IPKIFCryptoKeyID.h"
00014 #include "IPKIFCAPISource.h"
00015 #include "IPKIFCryptoKeyAgree.h"
00016 #include "components.h"
00017
00018 #include <wincrypt.h>
00019 #include <bitset>
00020
00021
00022 struct CPKIFCNGCAPIImpl;
00023 FD_LIST_PTR(CPKIFCredential);
00024 FD_SMART_PTR(CPKIFKeyUsage);
00025
00083 class CAC_API CPKIFCNGCAPI : public IPKIFColleague, public IPKIFCryptoKeyID, public IPKIFCAPISource, public IPKIFCryptoKeyAgree
00084 {
00085 friend struct CPKIFCNGCAPIImpl;
00086 public:
00087 CPKIFCNGCAPI(const char* provider = NULL, int provType = 0, int sysStoRegLoc = CERT_SYSTEM_STORE_CURRENT_USER);
00088 virtual ~CPKIFCNGCAPI(void);
00089
00090
00091 void Initialize();
00092
00093
00094 void GetKeyList(CPKIFCredentialList& v,std::bitset<9>* = NULL);
00095 void GetKeyList(CPKIFCredentialList& v, CPKIFKeyUsagePtr& ku);
00096
00097
00098 bool OwnsKey(const CPKIFCredential& keyID) const;
00099 CPKIFCredentialPtr MakeKeyID(const std::string& asciiHexKeyID);
00100
00101
00102 void Sign(const CPKIFCredential& key, unsigned char* pHashData, int nHashDataLen, unsigned char* pSignature, int* nSignatureLen, PKIFCRYPTO::HASH_ALG hashAlg);
00103 void Decrypt(const CPKIFCredential& key, unsigned char* pData, int nDataLen, unsigned char* pResult, int* pnResultLen);
00104 void Encrypt(const CPKIFCredential& key, unsigned char* pData, int nDataLen, unsigned char* pResult, int* pnResultLen);
00105 bool Verify(const CPKIFCredential& key, unsigned char* pHashData, int nHashDataLen, unsigned char* pSignature, int nSignatureLen, PKIFCRYPTO::HASH_ALG hashAlg);
00106
00107 IPKIFCryptContext* CryptInit(CPKIFCredentialPtr& key, bool pad = true);
00108 void Decrypt(IPKIFCryptContext* cryptContext, unsigned char* pData, int nDataLen, unsigned char* pResult, int* pnResultLen, bool final);
00109 void Encrypt(IPKIFCryptContext* cryptContext, unsigned char* pData, int nDataLen, unsigned char* pResult, int* pnResultLen, bool final);
00110
00111
00112
00113 virtual IPKIFKeyAgreeContextPtr SecretAgree(CPKIFCredentialPtr& myPrivateKey, const CPKIFCertificatePtr& theirCert,
00114 const CPKIFAlgorithm * alg);
00115 virtual IPKIFKeyAgreeContextPtr SecretAgree(CPKIFCredentialPtr& myPrivateKey, const CPKIFBufferPtr& theirPublicKey,
00116 const CPKIFAlgorithm * alg);
00117
00118
00119
00120 virtual IPKIFKeyAgreeContextPtr SecretAgree(const CPKIFCredentialPtr& myPrivateKey, CPKIFCredentialPtr & ephemeralKeyPair,
00121 const CPKIFCertificatePtr& theirCert, const CPKIFAlgorithm * alg);
00122 virtual IPKIFKeyAgreeContextPtr SecretAgree(const CPKIFCredentialPtr& myPrivateKey, CPKIFCredentialPtr & ephemeralKeyPair,
00123 const CPKIFBufferPtr& theirPublicKey, const CPKIFAlgorithm * alg);
00124
00125 virtual IPKIFKeyAgreeContextPtr SecretAgree(const CPKIFCredentialPtr& myPrivateKey, const CPKIFBufferPtr& ephemeralPublicKey,
00126 const CPKIFCertificatePtr& theirCert, const CPKIFAlgorithm * alg);
00127 virtual IPKIFKeyAgreeContextPtr SecretAgree(const CPKIFCredentialPtr& myPrivateKey, const CPKIFBufferPtr& ephemeralPublicKey,
00128 const CPKIFBufferPtr& theirPublicKey, const CPKIFAlgorithm * alg);
00129
00130 virtual CPKIFKeyMaterialPtr DeriveKey(const IPKIFKeyAgreeContextPtr & context, unsigned long keyLen);
00131
00132
00133 private:
00135 CPKIFCNGCAPI(const CPKIFCNGCAPI& copy);
00137 CPKIFCNGCAPI& operator=(const CPKIFCNGCAPI& rhs);
00138
00139 enum { thisComponent = TOOLKIT_CRYPTO_CAPI };
00140
00141 struct CPKIFCNGCAPIImpl *m_impl;
00142
00143 };
00144 DECLARE_SMART_POINTERS(CPKIFCNGCAPI);
00145
00146 #endif