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

CryptHash.h

Go to the documentation of this file.
00001 /*  CryptHash.h - cryto API hash 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_CryptHash_h
00027 #define OW32_CryptHash_h
00028 
00029 #include <OW32/XHCRYPTHASH.h>
00030 
00031 namespace OW32 {
00032 
00034 class OW32_LIB_EXPORT CCryptHash
00035 {
00036     XHCRYPTHASH m_hCryptHash;
00037 
00038     CCryptHash(const CCryptHash& cryptHash);
00039     CCryptHash operator=(const CCryptHash& cryptHash);
00040 
00041 public:
00043     CCryptHash() {}
00044 
00046     void Destroy()
00047     {
00048         m_hCryptHash.Close();
00049     }
00050 
00058     BOOL Create(HCRYPTPROV hProv, ALG_ID algId,
00059         HCRYPTKEY hKey = NULL, DWORD dwFlags = 0)
00060     {
00061         Destroy();
00062         return CryptCreateHash(hProv, algId, hKey, dwFlags, &m_hCryptHash);
00063     }
00064 
00071     BOOL Hash(const void* pbData, DWORD dwDataLen, DWORD dwFlags = 0)
00072     {
00073         return CryptHashData(m_hCryptHash, (const BYTE*)pbData, dwDataLen, dwFlags);
00074     }
00075 
00083     BOOL GetParam(DWORD dwParam, BYTE* pbData, DWORD* pdwDataLen, 
00084         DWORD dwFlags=0)
00085     {
00086         return CryptGetHashParam(m_hCryptHash, dwParam, pbData, 
00087             pdwDataLen, dwFlags);
00088     }
00089 
00094     BOOL GetSize(DWORD* pdwSize)
00095     {
00096         DWORD dwDataLen = sizeof(DWORD);
00097         return GetParam(HP_HASHSIZE, (BYTE*)pdwSize, &dwDataLen);
00098     }
00099 
00106     BOOL GetValue(PBYTE pbData, DWORD* pdwDataLen)
00107     {
00108         return GetParam(HP_HASHVAL, pbData, pdwDataLen);
00109     }
00110 
00115     BOOL GetAlgId(ALG_ID* pAlgId)
00116     {
00117         DWORD dwDataLen = sizeof(ALG_ID);
00118         return GetParam(HP_ALGID, (PBYTE)pAlgId, &dwDataLen);
00119     }
00120 
00122     operator HCRYPTHASH () const { return m_hCryptHash; }
00123 };
00124 
00125 } // namespace OW32
00126 
00127 #endif // OW32_CryptHash_h

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