c++ - Encryption/Decryption using bcrypt library -
i calling bcryptdecrypt
function returning error. error 120 using getlasterror
means function not supported in scheme (in msdn).
status = bcryptdecrypt( hkey, pbinput, cbinput, null, null, sizeof(dword), null, 0, &pcbresult, bcrypt_block_padding);
pbinput
pointer address contains info decrypted, cbinput
length of file , pcbresult
size of output file (decrypted data). bcryptencrypt
working fine bcryptdecryptis
not working.
can please help me out? few lines of code related decrypt:
status = bcryptopenalgorithmprovider(&halgorithm , bcrypt_aes_algorithm , null , 0); if (!nt_success(status)) { return; }
dword cbkey = 0; dword cbdata =0; status = bcryptsetproperty(halgorithm , bcrypt_chaining_mode , (pbyte)bcrypt_chain_mode_ecb , sizeof(bcrypt_chain_mode_ecb) , 0); if (!nt_success(status)) { return; } status = bcryptgetproperty(halgorithm, bcrypt_object_length, (lpbyte)&cbdata, sizeof(dword), &cbkey, 0); lpbyte pbkey = (byte*)heapalloc(getprocessheap() , 0 , cbdata); lpcstr szpwd = (lpcstr)getpwd(); bcrypt_key_handle hkey = null; status = bcryptgeneratesymmetrickey(halgorithm, &hkey, pbkey, cbdata, (puchar)szpwd, (ulong)strlen(szpwd), 0); if (!nt_success(status)) { if(halgorithm) { bcryptclosealgorithmprovider(halgorithm,0); } if(pbkey) { heapfree(getprocessheap(), 0, pbkey); } return; } dword pcbresult = 0; status = bcryptdecrypt( hkey, pbinput, cbinput, null, null, sizeof(dword), null, 0, &pcbresult, bcrypt_block_padding); dword cberror = getlasterror(); if(cberror != 0) { lpcstr messagebuffer = null; size_t size = formatmessagea(format_message_allocate_buffer | format_message_from_system | format_message_ignore_inserts, null, cberror, makelangid(lang_neutral, sublang_default), (lpstr)&messagebuffer, 0, null);
c++ encryption
No comments:
Post a Comment