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

**URL:** <https://forums.unrealengine.com/t/how-do-you-get-an-frsakeyhandle-from-a-public-rsa-key-file/610202>\
**Category:** C++\
**Tags:** unreal-engine, UE5-0, CPP, question\
**Created:** [July 21, 2022, 12:39pm UTC](https://forums.unrealengine.com/t/how-do-you-get-an-frsakeyhandle-from-a-public-rsa-key-file/610202 "2022-07-21T12:39:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CdrJameson](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CdrJameson](https://forums.unrealengine.com/u/CdrJameson)\
**Post date:** [July 21, 2022, 12:39pm UTC](https://forums.unrealengine.com/t/how-do-you-get-an-frsakeyhandle-from-a-public-rsa-key-file/610202/1 "2022-07-21T12:39:07Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![robyn.to](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@robyn.to](https://forums.unrealengine.com/u/robyn.to)\
**Post date:** [November 21, 2023, 12:13am UTC](https://forums.unrealengine.com/t/how-do-you-get-an-frsakeyhandle-from-a-public-rsa-key-file/610202/2 "2023-11-21T00:13:02Z")

</div>

bump

---

<div class="post-metadata">

**Author:** ![Alex\_data](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Alex\_data](https://forums.unrealengine.com/u/Alex_data)\
**Post date:** [February 23, 2024, 6:52am UTC](https://forums.unrealengine.com/t/how-do-you-get-an-frsakeyhandle-from-a-public-rsa-key-file/610202/3 "2024-02-23T06:52:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zhaojunmeng](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zhaojunmeng](https://forums.unrealengine.com/u/zhaojunmeng)\
**Post date:** [December 26, 2024, 3:51pm UTC](https://forums.unrealengine.com/t/how-do-you-get-an-frsakeyhandle-from-a-public-rsa-key-file/610202/4 "2024-12-26T15:51:56Z")

</div>

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

```auto
#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;
}

```
