간단하게 MD5 Hash 값을 만들어 주는 소스

MD5 이외에도 CRC32, GOSTHASH, MD2, MD4, SHA1, SHA2 를 지원한다.

URL : http://www.codeproject.com/cpp/chash.asp

예제코드

  1. // Define a CHash object  
  2. CHash hashObj;  
  3.   
  4. // Set the algorithm  
  5. hashObj.SetHashAlgorithm(MD5);  
  6.   
  7. // Set the operation  
  8. hashObj.SetHashOperation(STRING_HASH);  
  9.   
  10. // Set the string  
  11. hashObj.SetHashString("String to hash");  
  12.   
  13. // Hash the string  
  14. CString outHash = hashObj.DoHash();  

주의점 :
예전에 만들어진 소스여서 그런지, CRC32 지원코드가 최근 컴파일러와는 호환되지 않는다.
(테스트에 사용된 컴파일러는 VS2003이다.)
아래의 부분을 수정해서 CRC32 지원을 끄고 사용해야 한다.

filename : CHash.h

원래 코드
  1. // Choose which algorithms you want  
  2. // Put 1s to support algorithms, else 0 to not support  
  3. #define        SUPPORT_CRC32          1  
  4. #define        SUPPORT_GOSTHASH       1  

수정 후
  1. // Choose which algorithms you want  
  2. // Put 1s to support algorithms, else 0 to not support  
  3. #define        SUPPORT_CRC32          0  
  4. #define        SUPPORT_GOSTHASH       1  
반응형

'저장고 > C++' 카테고리의 다른 글

FormView 에 Dialog 붙이기  (2) 2007.10.09
원격 디버깅  (7) 2006.08.07
Memory Leak 을 쉽게 찾아보자!!  (2) 2006.06.01

+ Recent posts