i’m trying to send a rsa key (RSA *myrsa) over tcp connection such way:
send(client, (char *)myrsa, sizeof(RSA), 0);
and recipient does:
read_bytes = tcpSocket.read(buffer, sizeof(RSA));
RSA *myrsa = RSA_new();
memcpy((void*)myrsa, (void*)buffer, read_bytes);
then RSA_check_key(rsa) returns -1 or crashes the programm.
What i do wrong? Maybe it exists more proper solution? Maybe the row message corrupts by any transformings?
The -1 implies that there’s an error in the data. the RSA_check_keys method merely verifies that parameters are consistent, not that the data is necessarily valid.
Behaviour like a crash might also be consistent with bad data.
A couple of places where there might be issues:
Do you actually allocate room for buffer?
Do you check the length of read_bytes to make sure the data you received is likely an RSA key?