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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
/*
"businesspapers.doc" md5加密后 设置为DES CBC的key 然后去解密 BusinessPapers.doc文件 文件路径修改一下别出现中文 C:\abc\BusinessPapers.doc C:\abc\res.doc */
int main(int argc, char *argv[]) { int i; char* filename = "businesspapers.doc"; char* str = "thosefilesreallytiedthefoldertogether"; BYTE md5_data[100] = {0}; BYTE sha1_data[100] = {0}; DWORD md5_len = 16; DWORD sha1_len = 20; BYTE pbData[4]; *(DWORD *)pbData = 1; HCRYPTKEY phKey = 0; HCRYPTPROV phProv = 0; HCRYPTHASH phHash = 0; DWORD NumberOfBytesRead=0; HANDLE hFile = 0; HANDLE hObject = 0; BYTE lpBuffer[0x5000]={0}; int v18 = 0; if (!CryptAcquireContextW(&phProv, 0, 0, 0x18u,0)) { printf("wrong1\n"); return 0; } CryptCreateHash(phProv, 0x8004u, 0, 0, &phHash); CryptHashData(phHash, (BYTE*)str, 37, 0); CryptGetHashParam(phHash, 2u, sha1_data, &sha1_len, 0); CryptDeriveKey(phProv,0x6610u, phHash, 1u, &phKey); CryptDestroyHash(phHash); CryptSetKeyParam(phKey, 4u, pbData, 0); phHash = 0; CryptCreateHash(phProv, 0x8003u, 0, 0, &phHash); CryptHashData(phHash, (BYTE*)filename, strlen(filename), 0); CryptGetHashParam(phHash, 2u, md5_data, &md5_len, 0); for(i = 0;i < 16;i+=2) { printf("%02x",(DWORD)md5_data[i]); } printf("\n"); //CryptDestroyHash(phHash); if(!CryptSetKeyParam(phKey, 1u, md5_data, 0)) { printf("wrong2\n"); return 0; } hFile = CreateFile("C:\\abc\\BusinessPapers.doc", 0x80000000, 3u, 0, 3u, 0x80u, 0); if(hFile == (HANDLE)-1) { printf("wrong3\n"); return 0; } hObject = CreateFile("C:\\abc\\res.doc", 0x40000004u, 3u, 0, 3u, 0x80u, 0); if(hObject == (HANDLE)-1) { printf("wrong4\n"); return 0; } while ( ReadFile(hFile, lpBuffer,0x4000, &NumberOfBytesRead, 0) ) { if ( NumberOfBytesRead < 0x4000) { v18 = 1;} CryptDecrypt(phKey, 0, v18, 0, (BYTE *)lpBuffer, &NumberOfBytesRead); //CryptEncrypt(phKey, 0, v18, 0, (BYTE *)lpBuffer, &NumberOfBytesRead, 0x4010); WriteFile(hObject, lpBuffer, NumberOfBytesRead, &NumberOfBytesRead, 0); if ( v18 ) { break; } } return 0; } /* cl0se_t3h_f1le_0n_th1s_0ne@flare-on.com */
|