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

CryptContext.h

Go to the documentation of this file.
00001 /*  CryptContext.h - cryptoAPI context 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_CryptContext_h
00027 #define OW32_CryptContext_h
00028 
00029 #include <OW32/XHCRYPTPROV.h>
00030 
00031 namespace OW32
00032 {
00033 
00035 class OW32_LIB_EXPORT CCryptContext
00036 {
00037     XHCRYPTPROV m_hCryptProv;
00038 
00039     CCryptContext(const CCryptContext& );
00040     CCryptContext operator=(const CCryptContext& );
00041 
00042 public:
00043     CCryptContext() {}
00044 
00046     CCryptContext(HCRYPTPROV hCryptProv) {
00047         m_hCryptProv = hCryptProv;
00048     }
00049 
00050     operator HCRYPTPROV() { return m_hCryptProv; }
00051 
00052     BOOL AcquireContext(LPCTSTR ContainerName = NULL, LPCTSTR ProviderName = NULL,
00053         DWORD ProvType = PROV_RSA_FULL, DWORD dwFlags = 0)
00054     {
00055         m_hCryptProv.Close();
00056         return CryptAcquireContext(&m_hCryptProv, ContainerName, ProviderName,
00057             ProvType, dwFlags);
00058     }
00059 
00060     BOOL AcquireContextWithCreate(LPCTSTR ContainerName = NULL, LPCTSTR ProviderName = NULL,
00061         DWORD ProvType = PROV_RSA_FULL, DWORD dwFlags = 0)
00062     {
00063         if (AcquireContext(ContainerName, ProviderName, ProvType, dwFlags))
00064             return TRUE;
00065         // failed to acquire the container, create a new one
00066         return AcquireContext(ContainerName, ProviderName, ProvType, dwFlags|CRYPT_NEWKEYSET);
00067     }
00068 
00069     BOOL GetProvParam(DWORD dwParam, BYTE* pbData, DWORD* cbData, DWORD Flags = 0)
00070     {
00071         return CryptGetProvParam(m_hCryptProv, dwParam, pbData, cbData, Flags);
00072     }
00073 
00074     BOOL GetUserKey(DWORD KeySpec, HCRYPTKEY* phKey)
00075     {
00076         return CryptGetUserKey(m_hCryptProv, KeySpec, phKey);
00077     }
00078 
00079     BOOL GenKey(ALG_ID AlgId, HCRYPTKEY* phKey, DWORD Flags = 0)
00080     {
00081         return CryptGenKey(m_hCryptProv, AlgId, Flags, phKey);
00082     }
00083 
00084     BOOL GenRandom(DWORD dwLen, BYTE *pbBuffer)
00085     {
00086         return CryptGenRandom(m_hCryptProv, dwLen, pbBuffer);
00087     }
00088 
00089     BOOL ImportKey(BYTE* pbData, DWORD dwDataLen, HCRYPTKEY* phKey, HCRYPTKEY hPubKey = NULL, DWORD dwFlags = 0)
00090     {
00091         return CryptImportKey(m_hCryptProv, pbData, dwDataLen, hPubKey, dwFlags, phKey);
00092     }
00093 };
00094 
00095 } // namespace OW32
00096 
00097 #endif // OW32_CryptContext_h

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