So here's the program code that generates keys for the RSA algorithm. Should more precisely generate. But for some reason I can’t understand what the problem is. Error 33 line

/home/extra/listing1.cpp||In function 'int main()':| /home/extra/listing1.cpp|33|error: initializer expression list treated as compound expression| /home/extra/listing1.cpp|33|error: invalid conversion from 'const char*' to 'int'| ||=== Build finished: 2 errors, 0 warnings ===| #include <stdio.h> #include <openssl/rsa.h> #include <openssl/pem.h> using namespace std; /* Имена ключевых файлов */ #define PRIVAT "./privat.key" #define PUBLIC "./public.key" int main() { /* указатель на структуру для хранения ключей */ RSA * rsa = NULL; unsigned long bits = 2048; /* длина ключа в битах */ FILE *priv_key_file = NULL, *pub_key_file = NULL; /* контекст алгоритма шифрования */ const EVP_CIPHER *cipher = NULL; priv_key_file = fopen(PRIVAT, "wb"); pub_key_file = fopen(PUBLIC, "wb"); /* Генерируем ключи */ rsa = RSA_generate_key(bits, RSA_F4, NULL, NULL); /* Формируем контекст алгоритма шифрования */ OpenSSL_add_all_ciphers(); cipher = EVP_get_cipherbyname("bf-ofb"); /* Получаем из структуры rsa открытый и секретный ключи и сохраняем в файлах. * Секретный ключ шифруем с помощью парольной фразы "hello" */ int PEM_write_RSAPrivateKey(priv_key_file, rsa, cipher, 0, NULL, "hello"); PEM_write_RSAPublicKey(pub_key_file, rsa); /* Освобождаем память, выделенную под структуру rsa */ RSA_free(rsa); } 
  • 3
    The compiler writes that the error is in line 33. And where is this line in the above text? - skegg 9:39 pm
  • Those. the compiler wonders why line 33 begins with the magic word int , and the PEM_write_RSAPrivateKey parameters are messed up. Where there should be a function pointer, it says "hello". It does not understand this Hella. Probably your hella should be in place of 0, and the length of hella should be NULL. Well, one more parameter is missing in quantity - additional parameters of the callback. - alexlz
  • And, here @alexlz was not too lazy to find the line 33. There the compiler does not understand what you want to declare (he thinks so) with the int type and is greatly confused with the diagnostics (well, the string constant hooked him strongly). If the case, then you want to call the function PEM_write_RSAPrivateKey ()? In this case, you need to write int rc = PEM_write_RSAPrivateKey (...); The rc variable will have a return code. - avp
  • > /home/extra/listing1.cpp|33|error: cannot convert 'const char*' to 'int (*)(char*, int, int, void*)' for argument '6' to 'int PEM_write_RSAPrivateKey(FILE*, RSA*, const EVP_CIPHER*, unsigned char*, int, int (*)(char*, int, int, void*), void*)'| - mrVOZIK
  • one
    Are you kidding me? int PEM_write_RSAPrivateKey(FILE *fp, RSA *x, const EVP_CIPHER *enc, unsigned char *kstr, int klen, pem_password_cb *cb, void *u); hereinafter The cb argument is the callback to use when querying for the pass phrase used for encrypted PEM structures (normally only private keys). For the PEM write routines if the kstr parameter is not NULL then klen bytes at kstr are used as the passphrase and cb is ignored. The cb argument is the callback to use when querying for the pass phrase used for encrypted PEM structures (normally only private keys). For the PEM write routines if the kstr parameter is not NULL then klen bytes at kstr are used as the passphrase and cb is ignored. Put cb and u zeros in place. - alexlz

0