Crypto API 질문
개럭시
질문 제목 :crypto api 질문
쓰는방법은 알겠는데 왜 저렇게 써야하는질 모르겠음... 그냥 사용자가 입력한 암호키받고 그걸로 걍 바로 쓰면되지왜 해시값에 세션키를 처만드는지...
질문 내용 :
bool encryptfile( pchar szsource, pchar szdestination, pchar szpassword)//------------------------------------------------// 파라메터 정의// szsource : 입력으로 주어지는 파일명 원문을 담고 있다.// szdestination : 출력파일 이름. 암호화 되어 있다.// szpassword : 암호화에 사용될 키값대칭키 방식이기에 복호화에도 사용된다.
{file *hsource;file *hdestination;
hcryptprocryptprov hcryptprov;hcryptkey hkey;hcrypthash hhash;
pbyte pbbuffer;dword dwblocklen;dword dwbufferlen;dword dwcount;
// 입력 파일 열기if(hsource = fopen(szsource,rb)){ printf(the source plaintext file, %s, is open. \n, szsource);}else{ handleerror(error opening source plaintext file!);}
// 출력파일 열기if(hdestination = fopen(szdestination,wb)){printf(destination file %s is open. \n, szdestination);}else{handleerror(error opening destination ciphertext file!);}// 디폴트 csp의 핸들을 얻어온다. cryptoapi중 가장 첫번째 함수if(cryptacquirecontext(&hcryptprov,0,ms_enhanced_prov,prov_rsa_full,0 )){ printf(a cryptographic provider has been acquired. \n);}else{ handleerror(error during cryptacquirecontext!);}
//hash 오브젝트를 생성한다.if(cryptcreatehash( sp; hcryptprov, calg_md5, 0, 0, &hhash)){printf(a hash object has been created. \n);}else{handleerror(error during cryptcreatehash!\n);}
if(crypthashdata( hhash, (byte *)szpassword, strlen(szpassword), 0))//패스워드에 해쉬를 취한다.{printf(the password has been added to the hash. \n);}else{handleerror(error during crypthashdata. \n);}
if(cryptderivekey( hcryptprov, encrypt_algorithm, hhash, keylength, &hkey))// 해쉬 값을 이용하여 세션키를 생성한다.{ printf(an encryption key is derived from the password hash. \n);}else{ handleerror(error during cryptderivekey!\n);}
굵은글씨로 한부분 다 이해가안가요 ㅠㅠ
csp 핸들을 얻어오고, 해싱오브젝트를 만들어 사용자가 입력한 암호키로 해시값을 만들고만들어진 해시값으로 왜 세션키를 만들죠 ㅠㅠ?
이해가안대요 네이버에 찾아봐도 자료가 충분하지않고 소스만 덜렁있꼬 설명이 없어여 ...구글은 무능력한 영어지식에 좌절했슴미당... 수다님들 도와주세영..
쓰는방법은 알겠는데 왜 저렇게 써야하는질 모르겠음... 그냥 사용자가 입력한 암호키받고 그걸로 걍 바로 쓰면되지왜 해시값에 세션키를 처만드는지...