Click here to Skip to main content
15,898,371 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I wrote the following programs based on crypto++ as part of an application and tried to run the app after appropriately adding a crypto++ dynamic link library compiled from source code obtained from the official Crypto++ GitHub repository. Unfortunate visual studio reported a linkage error that had to do with std::string. After making efforts for some hours to resolve the linkage error, I decided it is best I work with the source code such that I can easily locate error points. I tried to use the header files to determine the implementation files but only ended up with linkage errors.

How can one determine all the necessary implementation files for a program.


//The basic header files
C++
include "modes.h"
#include "aes.h"
#include "filters.h"
#include "rijndael.h"
#include "osrng.h"



First program

C++
std::string encryptMessage(const std::string& message, const std::string& key)
{
    using namespace CryptoPP;
    byte iv[AES::BLOCKSIZE];
    memset(iv, 0x00, AES::BLOCKSIZE); // Initialize IV to all zeros
    std::string encryptedMessage;
    try
    {
        CBC_Mode<AES>::Encryption encryption;
        encryption.SetKeyWithIV((const byte*)key.data(), key.size(), iv);
        StringSource(message, true,
            new StreamTransformationFilter(encryption,
                new StringSink(encryptedMessage)
            )
        );
    }
    catch (const Exception& ex)
    {
        UNREFERENCED_PARAMETER(ex);

        return std::string();
    }
    return encryptedMessage;
}



The second program

C++
std::string decryptMessage(const std::string& encryptedMessage, const std::string& key)
{
    using namespace CryptoPP;
    byte iv[AES::BLOCKSIZE];
    memset(iv, 0x00, AES::BLOCKSIZE); // Initialize IV to all zeros
    std::string decryptedMessage;
    try
    {
        CBC_Mode<AES>::Decryption decryption;
        decryption.SetKeyWithIV((const byte*)key.data(), key.size(), iv);
        StringSource(encryptedMessage, true,
            new StreamTransformationFilter(decryption,
                new StringSink(decryptedMessage)
            )
        );
    }
    catch (const Exception& ex)
    {
        UNREFERENCED_PARAMETER(ex);

        return std::string();
    }
    return decryptedMessage;
}




The third program


C++
std::string CreateKey()
{
    CryptoPP::AutoSeededRandomPool prng;

    byte Key[CryptoPP::AES::DEFAULT_KEYLENGTH];

    prng.GenerateBlock(Key, sizeof(Key));

    std::string stKey;
    for (int i = 0; i < CryptoPP::AES::DEFAULT_KEYLENGTH; i++)
    {
        stKey.push_back(Key[i]);
    }

    return stKey;
}


What I have tried:

I spent two days trying to resolve the associated issues with numerous googlng.
Posted
Comments
Richard MacCutchan 29-Apr-24 3:47am    
Please use the Improve question link above, and add complete details of the error messages.
Rick York 29-Apr-24 10:15am    
I used the code presented here successfully : https://www.codeproject.com/Articles/34508/WinAES-A-C-AES-Class

1 solution

I would suggest that you go back to the github repository you started with, and ask there - we would have to fork / extract the source and try it locally to even start duplicating your problem and since we are likely to be even less familiar with the package than you, the original authors are the best place to start working with.
 
Share this answer
 
Comments
Gbenbam 29-Apr-24 6:46am    
Come on man relax! Life is easy. Someone might know a rule of thumb for doing this. No mortal knows everything. That is why we interact and share. One may have learned something by experience over a long period of time or after a long period of time. This makes such candidates for helping others get out of the time quagmire. Don't be hash, we are not enemies. Surely, you understand use of language. I wish you a pleasant day.
Dave Kreskowiak 29-Apr-24 10:01am    
He wasn't being harsh. Hs was telling you to go to the place where you are the most likely to find help on a library you got from another site.

If we were here to support the millions of projects on GitHub, the name of this site would no longer be Code Project. It would be GitHub!
Gbenbam 29-Apr-24 11:24am    
The tone of his reply was hash. There are a billion and one more pleasant way of saying the same thing. It is either that he was being deliberately hash or he is not the best in the use of language. You should be pleasant to strangers especially if the have not offended you or mean you no harm.
Dave Kreskowiak 29-Apr-24 12:15pm    
LOL. No, it wasn't. It was informative at worst.
Gbenbam 29-Apr-24 7:47am    
By the way, isn't it possible one or more of the authors of the library is on code project. It seems you have a very low estimation of code project.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900