프로그래밍

... | 2011. 11. 26. 04:09
Posted by 신이내린프로그래머
프로그래밍을 할때마다 느끼는 거지만 기본이 가장 중요한 것 같다. 화이팅
 

윈도우에서 제공하는 간단한 방식의 암복호화 소스

Programming/Security | 2011. 11. 26. 03:40
Posted by 신이내린프로그래머

#include <WinCrypt.h>
int Encrypt(LPCTSTR lpszIn, LPTSTR lpszOut, int nBufLen)
{
 int result = 0;

 HCRYPTPROV hProv;
    HCRYPTHASH hHash;
    HCRYPTKEY hKey; 
    CString  csPass = "PASSWORD";
 DWORD  dwLen = strlen(lpszIn);

    if(!CryptAcquireContext(&hProv, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, 0))
    {
        if(!CryptAcquireContext(&hProv, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_NEWKEYSET))
        {
            return -1;
        }
    }
 strcpy(lpszOut, lpszIn);
 
    CryptCreateHash(hProv, CALG_SHA, 0, 0, &hHash);
    CryptHashData(hHash, (BYTE*)(LPCTSTR)csPass, csPass.GetLength(), 0);
    CryptDeriveKey(hProv, CALG_RC4, hHash, 0x0080*0x10000, &hKey);
    CryptEncrypt(hKey, 0, TRUE, 0, (BYTE*)lpszOut, &dwLen, nBufLen);
    //CryptDecrypt(hKey, 0, TRUE, 0, (BYTE*)lpszOut, &dwLen);
    CryptDestroyHash(hHash);
    CryptReleaseContext(hProv, 0);
 return result;
}

int Decrypt(LPCTSTR lpszIn, LPTSTR lpszOut)
{
 int result = 0;
 
 HCRYPTPROV hProv;
    HCRYPTHASH hHash;
    HCRYPTKEY hKey; 
    CString  csPass = "PASSWORD";
 DWORD  dwLen = strlen(lpszIn);
 
    if(!CryptAcquireContext(&hProv, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, 0))
    {
        if(!CryptAcquireContext(&hProv, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_NEWKEYSET))
        {
            return -1;
        }
    }
 strcpy(lpszOut, lpszIn);
 
    CryptCreateHash(hProv, CALG_SHA, 0, 0, &hHash);
    CryptHashData(hHash, (BYTE*)(LPCTSTR)csPass, csPass.GetLength(), 0);
    CryptDeriveKey(hProv, CALG_RC4, hHash, 0x0080*0x10000, &hKey);
    CryptDecrypt(hKey, 0, TRUE, 0, (BYTE*)lpszOut, &dwLen);
    CryptDestroyHash(hHash);
    CryptReleaseContext(hProv, 0);
 
 return result;
}

'Programming > Security' 카테고리의 다른 글

버퍼 오버플로우  (0) 2011.12.04
웹메소드 중 Get방식과 Post방식  (0) 2011.12.04
FTP의 Active Mode 와 Passive Mode  (0) 2011.12.04
DES  (0) 2011.11.29
오픈소스 API  (0) 2011.11.26
 

error C2731: 'WinMain' : 함수를 오버로드할 수 없습니다

Programming/MFC | 2011. 11. 26. 02:19
Posted by 신이내린프로그래머
프로젝트 속성의 유니코드와 멀티바이트 세팅에 따른 에러 메시지로
멀티바이트의 경우에는 LPTSTR로 설정하면 되고 유니코드의 경우에는
LPWSTR 설정하면 된다.

'Programming > MFC' 카테고리의 다른 글

MFC 헤더 및 라이브러리파일 설명  (0) 2011.11.26
 

블로그 이미지

신이내린프로그래머

카테고리

Category (22)
Programming (19)
... (1)