Last active
January 4, 2017 02:09
-
-
Save MareArts/61394d706ec91f9579c18d454d5771dd to your computer and use it in GitHub Desktop.
MFC Endoe
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
http://study.marearts.com/2017/01/mfc-encode-decode-example-souce-code.html | |
bool CEPenService_PenCommunicatorDlg::Encode(CString id, CString pass, CString mac) | |
{ | |
//char *bBuff; | |
CString csFile; | |
FILE *pFile; | |
char bBuff[100]; | |
char * cid = WtoC(id); | |
char * cpass = WtoC(pass); | |
char * cmac = WtoC(mac); | |
sprintf_s(bBuff, "%s+%s+%s+", cid, cpass, cmac); | |
DWORD dwFileLen = sizeof(bBuff); | |
delete cid; | |
delete cpass; | |
delete cmac; | |
HCRYPTPROV hProv; | |
HCRYPTHASH hHash; | |
HCRYPTKEY hKey; | |
char csPass[100] = "rlawjdgus"; | |
// CSP(Crystographic Service Provider) 핸들 얻기 | |
if (!CryptAcquireContext(&hProv, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, 0)) | |
{ | |
if (!CryptAcquireContext(&hProv, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_NEWKEYSET)) | |
{ | |
//printf("encode fail"); | |
return false; | |
} | |
} | |
// 해쉬 만들기 | |
CryptCreateHash(hProv, CALG_SHA, 0, 0, &hHash); | |
// 해쉬 값 계산 | |
CryptHashData(hHash, (BYTE*)csPass, sizeof(csPass), 0); | |
// 키 만들기\tab | |
CryptDeriveKey(hProv, CALG_RC4, hHash, 0x0080 * 0x10000, &hKey); | |
// 암호화\tab | |
CryptEncrypt(hKey, 0, TRUE, 0, (BYTE*)bBuff, &dwFileLen, dwFileLen); | |
// 해쉬 없애기 | |
CryptDestroyHash(hHash); | |
// CSP 핸들 풀어주기 | |
CryptReleaseContext(hProv, 0); | |
FILE* fp; | |
// 암호화된 파일 저장하기 | |
fopen_s(&fp, "AutoLogIn.CPR", "wb"); | |
fwrite(bBuff, 1, dwFileLen, fp); | |
fclose(fp); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://study.marearts.com/2017/01/mfc-encode-decode-example-souce-code.html