C++/cryptohash Edit Diff Refresh Backlink Random Search History Help Setting Hide Show Contents 1. cryptohash 2. Usage 2.1. SHA-1 2.2. hexdigestfile 2.3. SHA-256 1. cryptohash # Microsoft Cryptographic Provider를 쉽게 사용할 수 있는 헬퍼 템플릿 클래스. cryptohash.h (6.41 KB) /* * Authod: Marius Bancila (http://mariusbancila.ro) * License: Code Project Open License * Disclaimer: The software is provided "as-is". No claim of suitability, guarantee, or any warranty whatsoever is provided. * Published: 19.09.2012 */ #pragma once #include #include #pragma comment(lib, "Advapi32.lib") ... 2. Usage # 2.1. SHA-1 # CString strMsg("ABCDE"); CString strHash; CT2CA pszConvertedAnsiString(strMsg); string msg(pszConvertedAnsiString); crypto::sha1_helper_t hash_helper; string hash = hash_helper.hexdigesttext(msg); strHash.Format(L"Result= %S", hash.c_str()); OutputDebugString(strHash); Result= 7be07aaf460d593a323d0db33da05b64bfdcb3a5 2.2. hexdigestfile # CString strFilename("C:\\test_file.exe"); CString strHash; CT2CA pszConvertedAnsiString(strFilename); string target(pszConvertedAnsiString); crypto::sha1_helper_t hash_helper; string hash = hash_helper.hexdigestfile(target.c_str()); if (hash.empty()) { CString str; str.Format(L"SHA1 HASH Error code: %d; Error message: %S", hash_helper.lasterror().errorCode, hash_helper.lasterror().errorMessage.c_str()); OutputDebugString(str); return FALSE; } strHash.Format(_T("Result= %S"), hash.c_str()); OutputDebugString(strHash); Result= a735aff97994ad5ec4db1762697cc7faeff3a2f0 2.3. SHA-256 # 알고리즘 추가 하려면 다음을 참조하여 패치한다. cryptohash.h *************** *** 91,98 **** if(!::CryptAcquireContext( &m_hCryptProv, NULL, ! NULL, ! PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET)) { m_lasterror = errorinfo_t(GetLastError(), "Failed to acquire cryptographic context."); --- 91,98 ---- if(!::CryptAcquireContext( &m_hCryptProv, NULL, ! MS_ENH_RSA_AES_PROV, ! PROV_RSA_AES, CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET)) { m_lasterror = errorinfo_t(GetLastError(), "Failed to acquire cryptographic context."); *************** *** 301,309 **** --- 301,311 ---- typedef cryptohash_t md4_t; typedef cryptohash_t md5_t; typedef cryptohash_t sha1_t; + typedef cryptohash_t sha256_t; typedef cryptohash_helper_t md2_helper_t; typedef cryptohash_helper_t md4_helper_t; typedef cryptohash_helper_t md5_helper_t; typedef cryptohash_helper_t sha1_helper_t; + typedef cryptohash_helper_t sha256_helper_t; } string msg("..."); crypto::sha256_helper_t hash_helper; string hash = hash_helper.hexdigesttext(msg, TRUE); C++ MD5 SHA-1 Usage cryptohash.h 이 글에는 0 개의 댓글이 있습니다. Please enable JavaScript to view the comments powered by Disqus. comments powered by Disqus