c++ - How to AES CBC encryption Using cryptoAPI -


i want encrypt file aes cbc mode encryption, using cryptoapi functions , set own key command-line (it change in code)

i imagine key (after change) 1a1dc91c907325c6 , tried in form:

hcryptprov hprov  = null; hcryptkey hkey    = null; dword dwbloblen; pbyte pbkeyblob = null; pbkeyblob = (pbyte)"1a1dc91c907325c6";  if(!cryptacquirecontext(&hprov, null,null, prov_rsa_aes,crypt_verifycontext)) {     printf(" error in acquirecontext 0x%08x \n",getlasterror()); }     if (!cryptimportkey(hprov,pbkeyblob,sizeof(pbkeyblob),0,crypt_exportable,&hkey )) {     printf("error 0x%08x in importing des key \n",getlasterror()); } 

but cryptimportkey failed

i don't know how use cryptoapi functions , it's parameters

i tested other codes , change parameters or function's call's order 2 weeks wasn't able this

please me [a big :)]

thank you

you should this:

if( ::cryptacquirecontext( &m_hcryptoprovider, null, null/*default*/, prov_rsa_aes, crypt_verifycontext ) ) {     //hash password     // calg_sha1 ok     // calg_aes_128 / calg_aes_256 => error     if( ::cryptcreatehash( m_hcryptoprovider, calg_sha1, 0, 0, &m_hhashpassword ) )     {         // hash password.          if( ::crypthashdata( m_hhashpassword, (byte *)password, (dword) _tcslen(password) * sizeof(tchar), 0 ) )         {             // session key hash             if( ::cryptderivekey( m_hcryptoprovider, calg_aes_256, m_hhashpassword, crypt_create_salt, &m_hcryptkey ) )             {                 trace( text("crypto-api ok\n") );                  return error_success;             }             else             {                 trace( text("error in cryptderivekey\n") );              }         }         else         {             trace( text("error in crypthashdata\n") );          }     }     else     {          trace( text("error in cryptcreatehash\n") );     } } else {     trace( text("error in cryptacquirecontext\n") ); } 

after need use cryptencrypt/cryptdecrypt encode/decode data.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -