Click here to Skip to main content
15,892,161 members
Articles / Programming Languages / C++

CHash 1.5 - An MFC hashing class

Rate me:
Please Sign up or sign in to vote.
4.09/5 (61 votes)
8 Aug 20052 min read 210.3K   8.5K   106  
An MFC implementation of hashing files and strings with CRC32, GOST-Hash, MD2, MD4, MD5, SHA-1 and SHA-2 (256/384/512).
// CHash.h : header file
//

#ifndef _CHASH_H
#define _CHASH_H

// Choose which algorithms you want
// Put 1s to support algorithms, else 0 to not support
#define        SUPPORT_CRC32          1
#define        SUPPORT_GOSTHASH       1
#define        SUPPORT_MD2            1
#define        SUPPORT_MD4            1
#define        SUPPORT_MD5            1
#define        SUPPORT_SHA1           1
#define        SUPPORT_SHA2           1

/////////////////////////////////////////////////////////////////////////////
// CHash definitions

class CHash
{
// Construction
public:
	CHash();   // Standard constructor
	CString DoHash();
	int GetHashAlgorithm();
	CString GetHashFile();
	int GetHashFormat();
	int GetHashOperation();
	CString GetHashString();
	int GetSHA2Strength();
	CString GOSTHash();
	CString MD2Hash();
	CString MD4Hash();
	CString MD5Hash();
	CString SHA1Hash();
	CString SHA2Hash();
	void SetHashAlgorithm(int Algo);
	void SetHashOperation(int Style);
	void SetHashFile(LPCSTR File);
	void SetHashFormat(int Style);
	void SetHashString(LPCSTR Hash);
	void SetSHA2Strength(int Strength);

// Implementation
protected:
	// Input string, algorithm, filename, formatting and such
	CString    hashString;
	int        hashAlgo;
	CString    hashFile;
	int        hashFormatting;
	int        hashStyle;
	int        hashOperation;
	int        sha2Strength;
	
	// Temporary working CString
	CString    tempHash;
};

// Definitions of some kind
#define        STRING_HASH            1
#define        FILE_HASH              2

#define        SIZE_OF_BUFFER         16000

// Algorithms
#define        CRC32                  1
#define        GOSTHASH               2
#define        MD2                    3
#define        MD4                    4
#define        MD5                    5
#define        SHA1                   6
#define        SHA2                   7

// Formatting options
#define        LOWERCASE_NOSPACES     1
#define        LOWERCASE_SPACES       2
#define        UPPERCASE_NOSPACES     3
#define        UPPERCASE_SPACES       4

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
CEO
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions