티스토리 뷰
Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #pragma comment(lib, "crypt32.lib") #include <stdio.h> #include <Windows.h> #include <wincrypt.h> void hexdump(unsigned char *p, unsigned int len) { unsigned char *line = p; unsigned int i, thisline, offset = 0; while (offset < len) { printf("%04x ", offset); thisline = len - offset; if (thisline > 16) thisline = 16; for (i = 0; i < thisline; i++) printf("%02x ", line[i]); for (; i < 16; i++) printf(" "); for (i = 0; i < thisline; i++) printf("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.'); printf("\n"); offset += thisline; line += thisline; } } int main(void) { unsigned char *cDataIn = (unsigned char*)"Hello World!"; DATA_BLOB dDataIn, dDataOut, dDataVerify; LPWSTR pDescrOut = NULL; dDataIn.cbData = strlen(cDataIn) + 1; dDataIn.pbData = cDataIn; CryptProtectData(&dDataIn, L"Tribal", NULL, 0, 0, CRYPTPROTECT_LOCAL_MACHINE, &dDataOut); CryptProtectData(&dDataIn, L"Tribal", NULL, 0, 0, 0, &dDataOut); CryptUnprotectData(&dDataOut, &pDescrOut, NULL, NULL, NULL, CRYPTPROTECT_UI_FORBIDDEN, &dDataVerify); hexdump(dDataOut.pbData, dDataOut.cbData); hexdump(dDataVerify.pbData, dDataVerify.cbData); return 0; } | cs |
Result
'Programming > C' 카테고리의 다른 글
[sqllite3] sqlcipher build for Windows (0) | 2018.10.23 |
---|---|
[C++] STL 함수 코드 정리 (0) | 2018.10.20 |
OLE read, write API (0) | 2018.07.27 |
[Socket] Socketpair 및 sendmsg, recvmsg (0) | 2018.07.20 |
[Windows] Makefile, batch 파일 예제 코드 저장본 (0) | 2018.04.03 |
댓글