# Ruby equivalent for php openssl\_pkey\_get\_public

**URL:** <https://www.ruby-forum.com/t/ruby-equivalent-for-php-openssl-pkey-get-public/183143>\
**Category:** Ruby\
**Created:** [February 8, 2010, 11:01pm UTC](https://www.ruby-forum.com/t/ruby-equivalent-for-php-openssl-pkey-get-public/183143 "2010-02-08T23:01:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![LiMan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f04885/32.png) [@LiMan](https://www.ruby-forum.com/u/LiMan)\
**Post date:** [February 8, 2010, 11:01pm UTC](https://www.ruby-forum.com/t/ruby-equivalent-for-php-openssl-pkey-get-public/183143/1 "2010-02-08T23:01:40Z")

</div>

Hello all

I have the php script where the password encoding done using the  
openssl:

$key = openssl\_get\_publickey($certificate);  
openssl\_public\_encrypt($pass,$userPassCrypted,  
$key,OPENSSL\_PKCS1\_PADDING);  
openssl\_free\_key($key);

Now I trying to make the same with ruby

require ‘openssl’  
cert = OpenSSL::X509::Certificate.new(certificate)  
public\_key = cert.public\_key  
passwordSSL = public\_key.public\_encrypt(password, 1)

The problem here is that these password encoding isn’t match

The certificate the same but the publick key  
in PHP is:  
-----BEGIN PUBLIC KEY-----  
…  
-----END PUBLIC KEY-----  
in ruby is:  
-----BEGIN RSA PUBLIC KEY-----  
…  
-----END RSA PUBLIC KEY-----

I guess here is the difference (keys body also not the same)…

How can I get inside ruby the same public key as in PHP? Or is it  
possible convert RSA key by somehow?

Or maybe I have to do it with another way?

Any suggestions highly appreciated.
