Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

WinCAPICryptoProvider.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 2002-2005 The Apache Software Foundation.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 /*
00018  * XSEC
00019  *
00020  * WinCAPICryptoProvider := Base class to handle Windows Crypto API
00021  *
00022  * Author(s): Berin Lautenbach
00023  *
00024  * $Id: WinCAPICryptoProvider.hpp,v 1.20 2005/06/04 11:30:26 blautenb Exp $
00025  *
00026  */
00027 
00028 #ifndef WINCAPICRYPTOPROVIDER_INCLUDE
00029 #define WINCAPICRYPTOPROVIDER_INCLUDE
00030 
00031 #include <xsec/framework/XSECDefs.hpp>
00032 #include <xsec/enc/XSECCryptoProvider.hpp>
00033 
00034 #if defined (HAVE_WINCAPI)
00035 
00036 #if defined (_WIN32_WINNT)
00037 #   undef _WIN32_WINNT
00038 #endif
00039 #define _WIN32_WINNT 0x0400
00040 #include <wincrypt.h>
00041 
00042 
00043 // For older versions of wincrypt.h
00044 
00045 #if !defined (PROV_RSA_AES)
00046 #   define PROV_RSA_AES      24
00047 #   define ALG_SID_AES_128   14
00048 #   define ALG_SID_AES_192   15
00049 #   define ALG_SID_AES_256   16
00050 #   define ALG_SID_AES       17
00051 #   define CALG_AES_128      (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES_128)
00052 #   define CALG_AES_192      (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES_192)
00053 #   define CALG_AES_256      (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_AES_256)
00054 #endif
00055 
00056 #define WINCAPI_BLOBHEADERLEN   0x08
00057 #define WINCAPI_DSSPUBKEYLEN    0x08
00058 #define WINCAPI_DSSSEEDLEN      0x18
00059 #define WINCAPI_RSAPUBKEYLEN    0x0C
00060 
00084  /*\@{*/
00085 
00086 class DSIG_EXPORT WinCAPICryptoProvider : public XSECCryptoProvider {
00087 
00088 
00089 public :
00090 
00107     WinCAPICryptoProvider(LPCSTR provDSSName = NULL, LPCSTR provRSAName = NULL, DWORD dwFlags = 0);
00108 
00109     virtual ~WinCAPICryptoProvider();
00110 
00112 
00115 
00126     virtual XSECCryptoHash          * hashSHA1();
00127 
00139     virtual XSECCryptoHash          * hashSHA(int length = 160);
00140     
00152     virtual XSECCryptoHash          * hashHMACSHA1();
00153 
00166     virtual XSECCryptoHash          * hashHMACSHA(int length = 160);
00167     
00178     virtual XSECCryptoHash          * hashMD5();
00179 
00196     virtual XSECCryptoHash          * hashHMACMD5();
00197 
00208     virtual XSECCryptoKeyHMAC       * keyHMAC(void);
00209 
00211 
00214 
00229     virtual XSECCryptoBase64        * base64();
00230 
00232 
00235 
00245     virtual XSECCryptoKeyDSA        * keyDSA();
00246 
00256     virtual XSECCryptoKeyRSA        * keyRSA();
00257 
00268     virtual XSECCryptoX509          * X509();
00269 
00271 
00274 
00279     HCRYPTPROV getProviderDSS(void) {return m_provDSS;}
00280 
00285     HCRYPTPROV getProviderRSA(void) {return m_provRSA;}
00286 
00291     HCRYPTPROV getApacheKeyStore(void) {return m_provApacheKeyStore;}
00292 
00305     static BYTE * b642WinBN(const char * b64, unsigned int b64Len, unsigned int &retLen);
00306 
00319     static unsigned char * WinBN2b64(BYTE * n, DWORD nLen, unsigned int &retLen);
00320 
00328     virtual bool algorithmSupported(XSECCryptoSymmetricKey::SymmetricKeyType alg);
00329 
00337     virtual bool algorithmSupported(XSECCryptoHash::HashType alg);
00338     
00349     virtual XSECCryptoSymmetricKey  * keySymmetric(XSECCryptoSymmetricKey::SymmetricKeyType alg);
00350 
00363     virtual unsigned int getRandom(unsigned char * buffer, unsigned int numOctets);
00364 
00365 
00367 
00370 
00375     virtual const XMLCh * getProviderName();
00376 
00378 
00379 
00380 private:
00381 
00382     HCRYPTPROV      m_provDSS;
00383     HCRYPTPROV      m_provRSA;
00384     HCRYPTPROV      m_provApacheKeyStore;
00385     LPCSTR          m_provDSSName;
00386     LPCSTR          m_provRSAName;
00387     bool            m_haveAES;
00388     DWORD           m_provRSAType;
00389 
00390 };
00391 
00392 /*\@}*/
00393 
00394 #endif /* HAVE_WINCAPI */
00395 #endif /* WINCAPICRYPTOPROVIDER_INCLUDE */
00396 

Generated on Sun Jul 3 17:37:26 2005 for XML-Security-C by  doxygen 1.4.2