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

WinCAPICryptoSymmetricKey.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  * XSECCryptoSymmetricKey := Bulk encryption algorithms should all be
00021  *                          implemented via this interface
00022  *
00023  * Author(s): Berin Lautenbach
00024  *
00025  * $Id: WinCAPICryptoSymmetricKey.hpp,v 1.7 2005/06/04 11:30:26 blautenb Exp $
00026  *
00027  */
00028 
00029 
00030 
00031 #ifndef WINCAPICRYPTOSYMMETRICKEY_INCLUDE
00032 #define WINCAPICRYPTOSYMMETRICKEY_INCLUDE
00033 
00034 #include <xsec/framework/XSECDefs.hpp>
00035 #include <xsec/enc/XSECCryptoSymmetricKey.hpp>
00036 
00037 #if defined (HAVE_WINCAPI)
00038 
00039 #if !defined(_WIN32_WINNT)
00040 #   define _WIN32_WINNT 0x0400
00041 #endif
00042 
00043 #include <wincrypt.h>
00044 
00045 #define WINCAPI_MAX_BLOCK_SIZE      32
00046 
00058 class DSIG_EXPORT WinCAPICryptoSymmetricKey : public XSECCryptoSymmetricKey {
00059 
00060 public :
00061 
00064     
00076     WinCAPICryptoSymmetricKey(HCRYPTPROV prov, XSECCryptoSymmetricKey::SymmetricKeyType type);
00077 
00085     virtual ~WinCAPICryptoSymmetricKey();
00086 
00088 
00091 
00096     virtual const XMLCh * getProviderName();
00097 
00106     virtual XSECCryptoKey * clone();
00107 
00109 
00112 
00121     SymmetricKeyType getSymmetricKeyType(void);
00122 
00134     void setKey(const unsigned char * key, unsigned int keyLen);
00135 
00152     virtual bool decryptInit(bool doPad = true,
00153                              SymmetricKeyMode mode = MODE_CBC,
00154                              const unsigned char * iv = NULL);
00155 
00180     virtual unsigned int decrypt(const unsigned char * inBuf, 
00181                                  unsigned char * plainBuf, 
00182                                  unsigned int inLength,
00183                                  unsigned int maxOutLength);
00184 
00204     virtual unsigned int decryptFinish(unsigned char * plainBuf,
00205                                        unsigned int maxOutLength);
00206 
00222     virtual bool encryptInit(bool doPad = true, 
00223                              SymmetricKeyMode mode = MODE_CBC,
00224                              const unsigned char * iv = NULL);
00225 
00246     virtual unsigned int encrypt(const unsigned char * inBuf, 
00247                                  unsigned char * cipherBuf, 
00248                                  unsigned int inLength,
00249                                  unsigned int maxOutLength);
00250 
00272     virtual unsigned int encryptFinish(unsigned char * plainBuf,
00273                                        unsigned int maxOutLength);
00274 
00276 
00279 
00298     static HCRYPTKEY createWindowsKey(const unsigned char * key, 
00299                                       unsigned int keyLen, 
00300                                       XSECCryptoSymmetricKey::SymmetricKeyType type,
00301                                       HCRYPTPROV * prov);
00302 
00303 
00304 
00305 private:
00306 
00307     // Unimplemented constructors
00308     
00309     WinCAPICryptoSymmetricKey();
00310     WinCAPICryptoSymmetricKey(const WinCAPICryptoSymmetricKey &);
00311     WinCAPICryptoSymmetricKey & operator= (const WinCAPICryptoSymmetricKey &);
00312 
00313     int decryptCtxInit(const unsigned char * iv);
00314     void encryptCtxInit(const unsigned char * iv);
00315 
00316     // Private variables
00317     SymmetricKeyType                m_keyType;
00318     SymmetricKeyMode                m_keyMode;      // ECB or CBC
00319     safeBuffer                      m_keyBuf;       // Holder of the key
00320     unsigned int                    m_keyLen;
00321     bool                            m_initialised;
00322     bool                            m_doPad;
00323 
00324     unsigned char                   m_lastBlock[WINCAPI_MAX_BLOCK_SIZE];
00325     unsigned int                    m_bytesInLastBlock;
00326     unsigned int                    m_blockSize;
00327     unsigned int                    m_ivSize;
00328 
00329     HCRYPTPROV                      m_p;
00330     HCRYPTKEY                       m_k;
00331 
00332 };
00333 
00334 #endif /* HAVE_WINCAPI */
00335 #endif /* WINCAPICRYPTOSYMMETRICKEY_INCLUDE */

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