# Help with encryption

**URL:** <https://www.ruby-forum.com/t/help-with-encryption/122696>\
**Category:** Rails\
**Created:** [December 10, 2007, 10:32pm UTC](https://www.ruby-forum.com/t/help-with-encryption/122696 "2007-12-10T22:32:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [December 10, 2007, 10:32pm UTC](https://www.ruby-forum.com/t/help-with-encryption/122696/1 "2007-12-10T22:32:27Z")

</div>

So I have this key information that I got by generating a private and  
public key in VB, but it gave it to me in the form of a modulus and  
exponent in an XML file. Now, I need to encrypt some stuff in ruby using  
that info. On this site:  
[http://blog.internautdesign.com/2007/11/2/ruby-openssl-rsa-public-key-from-modulus-and-exponent/comments/165](http://blog.internautdesign.com/2007/11/2/ruby-openssl-rsa-public-key-from-modulus-and-exponent/comments/165),  
they explain how to do that, but clearly this info is in integer format  
so I need to convert my stuff, which looks similar to:  
tzG8K55r0VFT0uwhQa+PEoavFOH7TF9X5TWfyYc1a6JfY91KWpaj0 into a smiliar  
format. Right now I am decoding it from Base64 which I assumes leave me  
with a Hex value, but I am unsure about how to proceed. Anyone have any  
ideas? Thanks,

-S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [December 11, 2007, 4:32pm UTC](https://www.ruby-forum.com/t/help-with-encryption/122696/2 "2007-12-11T16:32:43Z")

</div>

Shandy N. wrote:

> So I have this key information that I got by generating a private and  
> public key in VB, but it gave it to me in the form of a modulus and  
> exponent in an XML file. Now, I need to encrypt some stuff in ruby using  
> that info. On this site:  
> [http://blog.internautdesign.com/2007/11/2/ruby-openssl-rsa-public-key-from-modulus-and-exponent/comments/165](http://blog.internautdesign.com/2007/11/2/ruby-openssl-rsa-public-key-from-modulus-and-exponent/comments/165),  
> they explain how to do that, but clearly this info is in integer format  
> so I need to convert my stuff, which looks similar to:  
> tzG8K55r0VFT0uwhQa+PEoavFOH7TF9X5TWfyYc1a6JfY91KWpaj0 into a smiliar  
> format. Right now I am decoding it from Base64 which I assumes leave me  
> with a Hex value, but I am unsure about how to proceed. Anyone have any  
> ideas? Thanks,

If you are doing asymmetric encryption in Rails, I recommend the Sentry  
gem. It makes encrypting model attributes trivially easy. It also  
includes some documentation for how to work with keys, though I don’t  
recall anything on modulus/exponent format. Most encryption I’ve seen  
uses OpenSSL to generate a public/private key pair. If you aren’t  
required to use your VB-generated pair, you might want to think about  
going the standard way and generating a new pair using OpenSSL.

–  
Josh S.  
[http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [December 11, 2007, 5:13pm UTC](https://www.ruby-forum.com/t/help-with-encryption/122696/3 "2007-12-11T17:13:00Z")

</div>

Josh S. wrote:

> If you are doing asymmetric encryption in Rails, I recommend the Sentry  
> gem. It makes encrypting model attributes trivially easy. It also  
> includes some documentation for how to work with keys, though I don’t  
> recall anything on modulus/exponent format. Most encryption I’ve seen  
> uses OpenSSL to generate a public/private key pair. If you aren’t  
> required to use your VB-generated pair, you might want to think about  
> going the standard way and generating a new pair using OpenSSL.
> 
> –  
> Josh S.  
> [http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)

It’s really not an issue using the VB or Ruby generated keys, because I  
can get both to generate keys, the problem is that I need to be able to  
port the keys to be used by the other. For exmaple, if I generate my key  
in Ruby I need to get it into a format that VB can use it, but it seems  
that between the two languages it is apples and oranges. Right now I can  
get VB to generate an xml file holding the “parts” that make up a key,  
the problem happens when I try and get those parts into the correct  
format so ruby can use the key.

So if I have this:

private\_key = OpenSSL::PKey::RSA.new(1024)

I can set the modulus and exponent for the keys like this:

private\_key.n = …  
private\_key.e = …

The problms is that the keys from VB is just a lot of characters, for  
example:

PEoavFOH7TF9X5TWfyYc1aJfY91Wpaj0osU2t3gQk9cSpDWDhNHXjXa7oSAWScQNMmR8

and I need to make it look like this:

42112068797415937200008076003921911646192548127635288

Thanks,

-S
