How do you get an FRSAKeyHandle from a public RSA key file?

I have an RSA signed file and the public RSA key of the signer (as a text file).
I will validate the signature by calling IEngineCrypto::DecryptPublic() but first I need to turn my RSA key file into the FRSAKeyHandle that DecryptPublic() needs.

Does anyone know how to do this?

The only function I can see that creates an FRSAKeyHandle is CreateRSAKey() but that generates a new public/private keypair, it doesn’t take an existing public key.

Does anyone have any experience or examples for what must surely be a common use case for the crypto library?

3 Likes

bump

Just call FRSA::CreateKey, it needs a public exponent which is usually 65537 (0x010001), a private exponent and a modulus. Remember to make sure all input arrays contain a single little endian large integer, you can get it by calling FBase64::Decode with a PEM key string that has no header and tail.

FRSAKeyHandle is just a RSA pointer, the following code read a string which contains the pem’s content, and return the FRSAKeyHandle.

#include <openssl/pem.h>

FRSAKeyHandle ReadFromString(const std::string& KeyString)
{
	BIO* _BIO = BIO_new_mem_buf(KeyString.c_str(), KeyString.length());
	FRSAKeyHandle _RSA = static_cast<FRSAKeyHandle>(PEM_read_bio_RSA_PUBKEY(_BIO, nullptr, nullptr, nullptr));
	BIO_free(_BIO);
	return _RSA;
}