1

I want to implement AES encryption/decryption in visual studio (C++). I have gone through Compiling and Integrating Crypto++ into the Microsoft Visual C++ Environment + Running Sample program.

I have followed all the steps mentioned there and try to build the application but i got the LINKER ERRORS while compiling, below link is the reference for ERRORS I'm facing in the application.

https://www.dropbox.com/sh/32ajyx0vc6391q0/AACRYndRpbKynntADFgZUdXYa?dl=0

Can any one please let me know the solution for this error?

Thanks

jww
  • 97,681
  • 90
  • 411
  • 885
Ashok
  • 29
  • 4
  • Copy your error contents and paste it here in a plain text. Do not use external sites to host any images, use stackoverflow instead. What do you mean by _"visual basic (C++)"_? Is it C++ or VB? why did you even mentioned VB? – mrogal.ski Jul 11 '18 at 13:20
  • Thanks for response, i wrongly mentioned as Visual basic instead of visual studio(now edited), – Ashok Jul 11 '18 at 13:28
  • In your instructions the step that should fix this is part of step 6: "Now go to the Linker and the Select the Input and in the Additional Dependency Enter the cryptlib.lib path as shown in the picture". – Rup Jul 11 '18 at 13:41
  • The original article can be found at [Compiling and Integrating Crypto++ into the Microsoft Visual C++ Environment](https://www.codeproject.com/Articles/16388/Compiling-and-Integrating-Crypto-into-the-Microsof). There's no need to use the ripped article. The original article tells you how to fix the linker errors. – jww Jul 11 '18 at 16:36
  • thank you, now i have added "Additional Dependency" as shown in step 6 and also added required header files but still i'm getting below LINKING ERRORS. – Ashok Jul 12 '18 at 06:01
  • Since i couldn't paste all the error's here , i'm sharing the dropbox link – Ashok Jul 12 '18 at 06:17

2 Answers2

1

I solved this LINKING Errors by changing the CryptoPP version.

Previously I used CryptoPP version (7.0.0) in my visual studio 2010, now i have tried with CryptoPP version (5.6.2).

Now i can able to compile without any errors.

Thanks for your suggestions.

Ashok
  • 29
  • 4
  • It sounds like you were mixing/matching versions of the library. It sounded like that before but you did not state you had different versions of the library installed at different places. Your setup will probably succeed if you completely delete the old Crypto++ 5.6.2 files. – jww Jul 13 '18 at 06:19
0

I would advise you to drop cryptopp and use Windows built-in cryptography instead. This way, the major part of the code i.e. the algorithms will be supported by MS, and updated as a part of Windows update.

As a nice side effects it will build faster, the binary will be much smaller, and the required library, Advapi32.lib, is part of Windows SDK i.e. you’ll unlikely have linker issues.

See this answer for an example how to derive AES key from password. However the code there is less than ideal, instead I usually create simple RAII wrappers like this:

class Context
{
    HCRYPTPROV hProv = 0;
public:
    Context() : hProv( 0 ) {}
    ~Context()
    {
        if( 0 != hProv )
            CryptReleaseContext( hProv, 0 );
    }
    operator HCRYPTPROV () const
    {
        return hProv;
    }
    HRESULT open()
    {
        if( !CryptAcquireContext( &hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT ) )
            return GetLastHr();
        return S_OK;
    }
};

And do the same for other HCRYPT* handles I need.

Then see MSDN example code on how to encrypt data with that AES key.

Soonts
  • 20,079
  • 9
  • 57
  • 130
  • Man, you made no effort to answer the question. Perhaps you should open an new question where you can supply the answer. – jww Jul 11 '18 at 16:39
  • @jww Did you see "or let me know how to encrypt/decrypt the text with AES in C++(Windows)?" line in the OP's question? – Soonts Jul 11 '18 at 16:43