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); }
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/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*)'|- mrVOZIKint PEM_write_RSAPrivateKey(FILE *fp, RSA *x, const EVP_CIPHER *enc, unsigned char *kstr, int klen, pem_password_cb *cb, void *u);hereinafterThe 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