Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

CryptKey.h

Go to the documentation of this file.
00001 /*  CCryptKey.h.- cryptoAPI key wrapper
00002     Copyright (C) 2001-2004 Mark Weaver
00003     Written by Mark Weaver <mark@npsl.co.uk>
00004 
00005     Part of the Open-Win32 library.
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public
00017     License along with this library; if not, write to the
00018     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019     Boston, MA  02111-1307, USA.
00020 */
00021 
00026 #ifndef OW32_CryptKey_h
00027 #define OW32_CryptKey_h
00028 
00029 #include <OW32/XHCRYPTKEY.h>
00030 
00031 namespace OW32
00032 {
00033 
00035 class OW32_LIB_EXPORT CCryptKey
00036 {
00037     XHCRYPTKEY m_hCryptKey;
00038 
00039     CCryptKey(const CCryptKey& );
00040     CCryptKey operator=(const CCryptKey& );
00041 
00042 public:
00044     CCryptKey() {}
00045 
00047     CCryptKey(HCRYPTKEY hCryptKey) {
00048         m_hCryptKey = hCryptKey;
00049     }
00050 
00052     void Destroy()
00053     {
00054         m_hCryptKey.Close();
00055     }
00056 
00063     BOOL Gen(HCRYPTPROV hProv, ALG_ID AlgId, DWORD dwFlags=0)
00064     {
00065         m_hCryptKey.Close();
00066         return CryptGenKey(hProv, AlgId, dwFlags, &m_hCryptKey);
00067     }
00068 
00076     BOOL Derive(HCRYPTPROV hProv, ALG_ID AlgId, HCRYPTHASH hBaseData,
00077         DWORD dwFlags=0)
00078     {
00079         m_hCryptKey.Close();
00080         return CryptDeriveKey(hProv, AlgId, hBaseData, dwFlags, &m_hCryptKey);
00081     }
00082 
00091     BOOL Import(HCRYPTPROV hProv, BYTE* pbData, DWORD dwDataLen,
00092         HCRYPTKEY hPubKey=0, DWORD dwFlags=0)
00093     {
00094         m_hCryptKey.Close();
00095         return CryptImportKey(hProv, pbData, dwDataLen,
00096             hPubKey, dwFlags, &m_hCryptKey);
00097     }
00098 
00107     BOOL Decrypt(BYTE *pbData, DWORD *cbData, 
00108         BOOL bFinal = TRUE, HCRYPTHASH hHash = NULL, DWORD dwFlags = 0)
00109     {
00110         return CryptDecrypt(m_hCryptKey, hHash, bFinal, dwFlags, pbData, cbData);
00111     }
00112 
00123     BOOL Encrypt(BYTE *pbData, DWORD *cbData, DWORD cbBuf,
00124         BOOL bFinal = TRUE, HCRYPTHASH hHash = NULL, DWORD dwFlags = 0)
00125     {
00126         return CryptEncrypt(m_hCryptKey, hHash, bFinal, dwFlags, pbData, cbData, cbBuf);
00127     }
00128 };
00129 
00130 } // namespace OW32
00131 
00132 #endif // OW32_CryptKey_h

Generated on Sun Jun 5 01:29:17 2005 for OW32 by  doxygen 1.3.9.1