이거를 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로 옴겨서 할려고 하는데
잘몰라서 약간의 지원만해주세요~
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2676182 | 숫자 순서대로 배열하는법 | 권뉴 | 2024-11-24 |
2676152 | 기본적인거 하나 질문드립니다. | 개미 | 2024-11-24 |
2676124 | 함수선언관련 질문이에요~...털썩..수정완료 (2) | 가지 | 2024-11-24 |
2676092 | C언어 책 (2) | 아서 | 2024-11-24 |
2676065 | 웹사이트 또는 메신저 등에서 원하는 텍스트를 검사하는방법?? (1) | 모든 | 2024-11-23 |
2676033 | 배열 기초연습중 발생하는 에러 ㅠㅜ... | Creative | 2024-11-23 |
2676005 | keybd_event 게임 제어 | 영글 | 2024-11-23 |
2675900 | 진짜기본적인질문 | 글길 | 2024-11-22 |
2675845 | 수정좀해주세요ㅠㅠㅠ | 해골 | 2024-11-21 |
2675797 | 병합 정렬 소스 코드 질문입니다. (2) | 도래솔 | 2024-11-21 |
2675771 | 큐의 활용이 정확히 어떻게 되죠?? | 해긴 | 2024-11-21 |
2675745 | 도서관리 프로그램 질문이요 | 도리도리 | 2024-11-20 |
2675717 | 2진수로 변환하는것! (3) | 동생몬 | 2024-11-20 |
2675599 | for문 짝수 출력하는 법 (5) | 널위해 | 2024-11-19 |
2675575 | Linux 게시판이 없어서.. | 첫삥 | 2024-11-19 |
2675545 | 구조체 이용할 때 함수에 자료 넘겨주는 것은 어떻게 해야 하나요? | 아연 | 2024-11-19 |
2675518 | 사각형 가로로 어떻게 반복해서 만드는지좀.. 내용 | 신당 | 2024-11-18 |
2675491 | !느낌표를 입력하는것은 어떻게합니까~~?ㅠㅠ (5) | 사지타리우스 | 2024-11-18 |
2675411 | 파일입출력으로 받아온 파일의 중복문자열을 제거한 뒤 파일출력 | 앨버트 | 2024-11-17 |
2675385 | 링크드리스트 주소록 질문드립니다. (1) | 겨루 | 2024-11-17 |