2

I switched over my IDE and compiler from Code::Blocks which was using MinGW, and I am now using Visual Studios. My code compiled and executed fine in Code::Blocks, but now I am getting a compile time error in Visual Studio saying

error C2027: use of undefined type 'rsa_st'

Here is the code section where the error exists:

uint8_t* getAESKey(RSAKeypair* keys, Fileinformation* encrypted)
{
    RSA *rsa = RSA_new();

    rsa->n = BN_bin2bn(keys->mod,128,0);
    rsa->e = BN_bin2bn(keys->pub_key,4,0);
    rsa->d = BN_bin2bn(keys->priv_key,128,0);

    unsigned char* dest = new unsigned char[32];

    int numbytes = RSA_private_decrypt(128,(const unsigned char*)encrypted->aeskey,dest,rsa,RSA_PKCS1_PADDING);

    return (uint8_t*)dest;
}

I believe I correctly configured the build options to include the include openssl directory. I am not getting any other errors on other function calls such as EVP_CIPHER_CTX_free

jww
  • 97,681
  • 90
  • 411
  • 885
Matthew
  • 3,886
  • 7
  • 47
  • 84
  • 1
    In case it matters... You we able to access RSA's members like `e`, `d` and `n` in OpenSSL 1.0.2 and below. OpenSSL 1.1.0 and above made them private. You have to use setter functions like [`RSA_set0_key`](https://www.openssl.org/docs/man1.1.0/crypto/RSA_set0_key.html), and getter functions like [`RSA_get0_key`](https://www.openssl.org/docs/man1.1.0/crypto/RSA_set0_key.html). Also see [Error: “invalid use of incomplete type ‘RSA {aka struct rsa_st}” in OpenSSL 1.1.0](http://stackoverflow.com/q/40549318). – jww Dec 27 '16 at 16:07
  • Thank you! That worked! Now I have link errors though... and idea? `error LNK2019: unresolved external symbol _OPENSSL_config` – Matthew Dec 27 '16 at 16:45
  • For missing libraries, see [How to add Additional libraries in C++](http://stackoverflow.com/q/4445418), [How to include libraries in Visual Studio 2012?](http://stackoverflow.com/q/20058864), and friends – jww Dec 27 '16 at 17:11
  • Thank you. I followed those steps and no luck. I will be creating another question with screen shots. FYI, thank you for solving the first issue with the RSA_set0_key function – Matthew Dec 27 '16 at 17:40
  • http://stackoverflow.com/questions/41350360/link-error-with-openssl-compiling-on-visual-studio-2010-unresolved-external-symb – Matthew Dec 27 '16 at 18:31

0 Answers0