Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CryptEncrypt and CryptDecrypt functions of CryptoApi problems

CryptEncrypt and CryptDecrypt functions of CryptoApi problems

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++dockeralgorithmssecurity
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    naeemnimi
    wrote on last edited by
    #1

    Hello: I am having following error while using CryptEncrypt and CryptDecrypt for public private key pair of Windows CryptoApi .I am using windowsXP as OS. The code of the class I am using is given below. I am having problem while using Encrypt and Decrypt functions of the class. Can anybody would tell me where is the error and how to remove it or could make the code right where error occurs. Thanks, Naeem //////////////////////////////Header File///////////////////////// #define _WIN32_WINNT 0x0400 #include #include #include // Helper class definition to generate and export Public/Private keys // for Asymmetric encryption. The semantics for usage are: // Call AcquireContext with a container name, call // GenerateKeyPair next and then call ExportPublicKey or // ExportPrivateKey. class CryptoHelper { private: HCRYPTPROV m_hCryptProv; HCRYPTKEY m_hSessionKey; BYTE *m_pPublicKey; BYTE *m_pPrivateKey; BYTE *m_pEncSessionKey; DWORD dwPrivateKeyLen; DWORD dwPublicKeyLen; DWORD dwEncSessionKeyLen; public: HCRYPTKEY m_hCryptKey; CryptoHelper(); ~CryptoHelper(); HRESULT AcquireContext(LPCTSTR wszContainerName); HRESULT GenerateKeyPair(); HRESULT ExportPublicKey(BYTE **ppPublicKey, DWORD &cbKeySize);; HRESULT ExportPrivateKey(BYTE **ppPrivateKey, DWORD &cbKeySize); void Encrypt(char **Input,char **Output,DWORD &dwLen); void Decrypt(char **Input,char **Output,DWORD &dwLen); }; //////////////////////////////The CPP File///////////////////////// #include "CryptoHelper.h" #include //#include "Cspdk.h" // The RSA public-key key exchange algorithm #define ENCRYPT_ALGORITHM CALG_RSA_KEYX // The high order WORD 0x0200 (decimal 512) // determines the key length in bits. #define KEYLENGTH 0x02000000 #define SESS_KEYLENGTH 0x00800000 //128 Bit //-------------------------------------------------------------------- // The constructor initializes the member variables // to NULL. //-------------------------------------------------------------------- CryptoHelper::CryptoHelper() { m_hCryptProv = NULL; m_hCryptKey = NULL; m_hSessionKey = NULL; m_pPublicKey=NULL; m_pPrivateKey=NULL; m_pEncSessionKey=NULL; dwPrivateKeyLen=0; dwPublicKeyLen=0; dwEncSessionKeyLen=0; } //-----------------------------------------------

    E 1 Reply Last reply
    0
    • N naeemnimi

      Hello: I am having following error while using CryptEncrypt and CryptDecrypt for public private key pair of Windows CryptoApi .I am using windowsXP as OS. The code of the class I am using is given below. I am having problem while using Encrypt and Decrypt functions of the class. Can anybody would tell me where is the error and how to remove it or could make the code right where error occurs. Thanks, Naeem //////////////////////////////Header File///////////////////////// #define _WIN32_WINNT 0x0400 #include #include #include // Helper class definition to generate and export Public/Private keys // for Asymmetric encryption. The semantics for usage are: // Call AcquireContext with a container name, call // GenerateKeyPair next and then call ExportPublicKey or // ExportPrivateKey. class CryptoHelper { private: HCRYPTPROV m_hCryptProv; HCRYPTKEY m_hSessionKey; BYTE *m_pPublicKey; BYTE *m_pPrivateKey; BYTE *m_pEncSessionKey; DWORD dwPrivateKeyLen; DWORD dwPublicKeyLen; DWORD dwEncSessionKeyLen; public: HCRYPTKEY m_hCryptKey; CryptoHelper(); ~CryptoHelper(); HRESULT AcquireContext(LPCTSTR wszContainerName); HRESULT GenerateKeyPair(); HRESULT ExportPublicKey(BYTE **ppPublicKey, DWORD &cbKeySize);; HRESULT ExportPrivateKey(BYTE **ppPrivateKey, DWORD &cbKeySize); void Encrypt(char **Input,char **Output,DWORD &dwLen); void Decrypt(char **Input,char **Output,DWORD &dwLen); }; //////////////////////////////The CPP File///////////////////////// #include "CryptoHelper.h" #include //#include "Cspdk.h" // The RSA public-key key exchange algorithm #define ENCRYPT_ALGORITHM CALG_RSA_KEYX // The high order WORD 0x0200 (decimal 512) // determines the key length in bits. #define KEYLENGTH 0x02000000 #define SESS_KEYLENGTH 0x00800000 //128 Bit //-------------------------------------------------------------------- // The constructor initializes the member variables // to NULL. //-------------------------------------------------------------------- CryptoHelper::CryptoHelper() { m_hCryptProv = NULL; m_hCryptKey = NULL; m_hSessionKey = NULL; m_pPublicKey=NULL; m_pPrivateKey=NULL; m_pEncSessionKey=NULL; dwPrivateKeyLen=0; dwPublicKeyLen=0; dwEncSessionKeyLen=0; } //-----------------------------------------------

      E Offline
      E Offline
      Elmue
      wrote on last edited by
      #2

      And why don't you use the button "Code Block" when posting code ? Your posting is completely unreadable.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups