Created
December 3, 2018 08:34
-
-
Save chung96vn/b4c7bc2ac9d506d2e71b591b6bb64e6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HCRYPTPROV hProv; | |
char filename[MAX_PATH]; | |
memset(filename, 0, MAX_PATH); | |
GetModuleFileNameA(NULL, filename, MAX_PATH); | |
char *key = strrchr(filename, '\\') + 1; | |
if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { | |
return NULL; | |
} | |
HCRYPTHASH hHash; | |
if (!CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash)) { | |
DWORD dwStatus = GetLastError(); | |
printf("CryptCreateHash failed: %x\n", dwStatus); | |
CryptReleaseContext(hProv, 0); | |
return NULL; | |
} | |
if (!CryptHashData(hHash, (BYTE*)key, strlen(key), 0)) { | |
DWORD err = GetLastError(); | |
printf("CryptHashData Failed : %#x\n", err); | |
CryptReleaseContext(hProv, 0); | |
CryptDestroyHash(hHash); | |
return NULL; | |
} | |
HCRYPTKEY hKey; | |
if (!CryptDeriveKey(hProv, CALG_AES_128, hHash, 0, &hKey)) { | |
DWORD dwStatus = GetLastError(); | |
printf("CryptDeriveKey failed: %x\n", dwStatus); | |
CryptReleaseContext(hProv, 0); | |
CryptDestroyHash(hHash); | |
return NULL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment