# Modulus and Exponent

**URL:** <https://www.ruby-forum.com/t/modulus-and-exponent/196536>\
**Category:** Ruby\
**Created:** [December 6, 2007, 10:16pm UTC](https://www.ruby-forum.com/t/modulus-and-exponent/196536 "2007-12-06T22:16:15Z")\
**Posts on this page:** 2\
**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 6, 2007, 10:16pm UTC](https://www.ruby-forum.com/t/modulus-and-exponent/196536/1 "2007-12-06T22:16:15Z")

</div>

Is there a way to get the modulus and exponent from an key, or is there  
a way to get that information as it is being encrypted? I am using the  
OpenSSL::PKey::RSA library to encrypt my data. 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 8, 2007, 12:48am UTC](https://www.ruby-forum.com/t/modulus-and-exponent/196536/2 "2007-12-08T00:48:17Z")

</div>

On Dec 6, 2007 1:16 PM, Shandy N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is there a way to get the modulus and exponent from an key, or is there  
> a way to get that information as it is being encrypted? I am using the  
> OpenSSL::PKey::RSA library to encrypt my data. Thanks,

It’s in ext/openssl/ossl\_pkey\_rsa.c:ossl\_rsa\_get\_params

sh-2.05b$ openssl genrsa -out test.pem 512  
Generating RSA private key, 512 bit long modulus  
…++++++++++++  
.++++++++++++  
e is 65537 (0x10001)  
sh-2.05b$ cat sslparams.rb  
require ‘openssl’  
file = ARGV[0] || “test.pem”  
OpenSSL::PKey::RSA.new(File.read(file)).params.each do |k,v|  
puts “#{k} = #{v}”  
end  
sh-2.05b$ ruby sslparams.rb  
iqmp =  
59260111929228437887497692691757636132892230319984822766526877098035186370601  
n =  
11804463841624570992464253395735827528891316877747581110813958174030871384082650715713947258948719543061592249783350178655531273368202635182086293357491941  
d =  
11689187633396551317545091362483299497115519346555148562621014749226871236290914623323220129606434399743927309247086015156374960675693636631059313239642145  
p =  
112801836523523861906861645509931518041464374339361561066100421492644618944537  
e = 65537  
q =  
104647798346464426891710400199240987063553868486458584292121861850498642450093  
dmq1 =  
99023959205578397450133824684619830214173568429859912795458096383091586608213  
dmp1 =  
53486077635053542407429782172225184600126728910320284879214346062284381856073

-Adam
