# RSA Key Question

**URL:** <https://www.ruby-forum.com/t/rsa-key-question/91693>\
**Category:** Ruby\
**Created:** [April 11, 2007, 5:21pm UTC](https://www.ruby-forum.com/t/rsa-key-question/91693 "2007-04-11T17:21:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![studlee2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/278dde/32.png) [@studlee2](https://www.ruby-forum.com/u/studlee2)\
**Post date:** [April 11, 2007, 5:21pm UTC](https://www.ruby-forum.com/t/rsa-key-question/91693/1 "2007-04-11T17:21:12Z")

</div>

I want to hardcode a public RSA key into a Ruby script so there is no  
reliance on an external ‘.pem’ file. When I do that the object is of  
type string and OpenSSL throws an error.

How can I get the “pub\_key = OpenSSL::PKey::RSA.new()” to recognize the key?

Thanks,  
\_Stud

---

<div class="post-metadata">

**Author:** ![studlee2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/278dde/32.png) [@studlee2](https://www.ruby-forum.com/u/studlee2)\
**Post date:** [April 11, 2007, 5:39pm UTC](https://www.ruby-forum.com/t/rsa-key-question/91693/2 "2007-04-11T17:39:16Z")

</div>

If it expects a file, try a StringIO object with your key:

require ‘stringio’  
key = StringIO.new(“hardcoded key”)  
pub\_key = OpenSSL:PKey::RSA.new(key)
