이거를 mfc로 옴기려고 하는데 조금만 도와주세요..
에드가
#include windows.h
#include wincrypt.h
#include stdio.h
#define KEYLENGTH 0x00380000
void HandleError(char *s);
#define ENCRYPT_ALGORITHM CALG_RC4
#define ENCRYPT_BLOCK_SIZE 8
BOOL EncryptFile(
PCHAR szSource,
PCHAR szDestination,
PCHAR szPassword);
void main(void)
{
PCHAR szSource;
PCHAR szDestination;
PCHAR szPassword;
if(!(szSource=(char *)malloc(100)))
HandleError(Memory allocation failed.);
if(!(szDestination=(char *)malloc(100)))
HandleError(Memory allocation failed.);
if(!(szPassword=(char *)malloc(100)))
HandleError(Memory allocation failed.);
printf(Encrypt a file. \n\n);
printf(Enter the name of the file to be encrypted: );
scanf(%s,szSource);
printf(Enter the name of the output file: );
scanf(%s,szDestination);
printf(Enter the passwordL );
scanf(%s,szPassword);
if(EncryptFile(szSource, szDestination, szPassword))
{
printf(Encryption of the file %s was a success. \n, szSource);
printf(The encrypted data is in file %s. \n, szDestnation);
}
else
{
printf(Error encrypting file!.);
}
getchar();
}
BOOL EncryptFile(
PCHAR szSource,
PCHAR szDestination,
PCHAR szPassword)
{
FILE *hSource;
FILE *hDestination;
HCRYPTPROV hCryptProv;
HCRYPTKEY hKey;
HCRYPTHASH hHash;
PBYTE pbBuffer;
DWORD dwBlickLen;
DWORD dwBufferLen;
DWORD dwCount;
if(hSource = fopen(szSource,rb))
{
printf(The source plaintext file, %s, is open. \n,szSource);
}
else
{
printf(Eroo opening source plaintext file!);
}
if(hDestination = fopen(szDestinationm wb))
{
printf(Destination file %s is open. \n,szDestination);
}
else
{
printf(Error opening destination ciphertext file!);
}
if(CryptAcquireContext(
&hCryptProv,
0,
MS_ENHANCED_PROV,
PROV_RSA_FULL,
0))
{
printf(A cryptographic provider has been acqurired. \n);
}
else
{
printf(Error during CryptAcquireContext!);
}
if(CryptCreateHash(
hCryptProv,
CALG_MD5,
0,
0,
&hHash))
{
printf(A hash object has been created. \n);
}
else
{
printf(Error during CryptCreateHash!\n);
}
if(cryptHashData(
hHash,
(BYTE *)szPassword,
Strlen(szPasswrod),
0))
{
printf(The password has been added to the hash. \n);
}
else
{
printf(Error during CryptHashData. \n);
}
if(cryptDeriveKey(
hCryptProv,
ENCRYPT_ALGORITHM,
hHash,
KEYLENGTH,
%hKey))
{
printf(An encryption key is derived from password hash. \n);
}
else
{
printf(Error during CryptDeriveKey!\n);
}
CryptDestroyHash(hHash);
hHash = 0;
dwBlockLen = 1000 - 1000 % ENCRYPT_BLOCK_SIZE;
if(ENCRYPT_BLOCK_SIZE 1)
dwBufferLen = dwBlockLen + ENCRYPT_BLOCK_SIZE;
else
dwBufferLen = dwBlockLen;
if(pbBuffer = (BYTE *)malloc(dwBufferLen + 1))
{
printf(Memory has been allocated for the buffer. \n);
}
else
{
printf(Out of memory. \n);
}
memset(pbBuffer, 0, dwBufferLen + 1 );
do
{
dwCount = fread(pbBuffer, 1, dwBlockLen, hSource);
if(ferror(hSource))
{
printf(Error reading plaintext!\n);
}
if(!CryptEncrypt(
hKey,
0,
feof(hSource),
0,
pbBufer,
&dwCount,
dwBufferLen))
{
printf(Error during CryptEncrypt. \n);
}
fwrite(pbBuffer, 1, dwCount, hDestination);
if(ferror(hDestination))
{
printf(Error writing ciphertext.);
}
}
while(!feof(hSource));
if(hSource)
fclose(hSource);
if(hDestination)
fclose(hDestination);
if(pbBuffer)
free(pbBuffer);
if(hKey)
CryptDestoryKey(hKey);
if(hHash)
CryptDestoryKey(hHash);
if(hCryptProv)
CryptReleaseContext(hcryptProv, 0);
trturn(TRUE);
}
fprintf(stderr, %s, (LPCTSTR) lpMsgBuf);
getchar();
exit(1);
}
이건데요 이거를 mfc로 옴겨서 할려고 하는데
잘몰라서 약간의 지원만해주세요~
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692256 | scanf("%*c"); ㅠㅠ 고수님들 | 거북이 | 2025-04-21 |
2692230 | 하노이탑 질문입니다. (1) | 미쁘다 | 2025-04-21 |
2692210 | 정보 올림피아드 문제인데.. 풀이 과정이 궁금합니다.(재귀함수) (5) | 물티슈 | 2025-04-20 |
2692144 | C언어와 리눅스에 대한 질문입니다. | 싴흐한세여니 | 2025-04-20 |
2692114 | 컨텍스트 스위칭하는데 걸리는 시간 측정.. | YourWay | 2025-04-19 |
2692086 | 간접참조 연산자, 증감연산자 질문이용! (2) | 블랙캣 | 2025-04-19 |
2692056 | 주석좀 달아주세요. 몇개적엇는데 몇개만달아주세요. (2) | DevilsTears | 2025-04-19 |
2691978 | 진수 쉽게 이해하는법... (3) | 지지않는 | 2025-04-18 |
2691949 | getchar() 한 문자를 입력받는 함수 질문 | 채꽃 | 2025-04-18 |
2691919 | 배열 정렬 및 합치기 질문입니다. | 사과 | 2025-04-18 |
2691845 | c언어왕초보 질문이 있습니다........ | 루나 | 2025-04-17 |
2691815 | void add(int num); 함수... (4) | 살랑살랑 | 2025-04-17 |
2691756 | 명령 프롬프트 스크롤바가 없어요 | 두메꽃 | 2025-04-16 |
2691725 | 자료구조에 관련해서 질문이 있어 글을 올립니다. | 누리알찬 | 2025-04-16 |
2691697 | if 문에서 구조체 배열에 저장되있던 문자열 검사하는 법 ? (2) | 민트맛사탕 | 2025-04-16 |
2691678 | C언어 함수 질문이요~!!! | 연보라 | 2025-04-15 |
2691650 | 반복문 | 돋가이 | 2025-04-15 |
2691618 | 링크드리스트 개념 질문이예요 (3) | 맨마루 | 2025-04-15 |
2691592 | 동적할당 이용 배열선언 질문입니다.ㅠㅠ (3) | 허리달 | 2025-04-15 |
2691542 | /=의 용도를 알려주세요 ㅠㅠ! (2) | 아라 | 2025-04-14 |