Forum: Ruby RSA Encryption Decryption

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B31966e5b7926566eb11c2ea96fc1c3d?d=identicon&s=25 name pipe (Guest)
on 2006-04-18 10:43
(Received via mailing list)
Hi,

I would like to know how can we do encryption and decryption using
public
and private keys in ruby. Does ruby any RSA libraries for the same. A
small
example would be quite helpful.

Thanks
5c6dae370b5f447866747b5c6691608e?d=identicon&s=25 Roland Schmitt (Guest)
on 2006-04-18 11:14
(Received via mailing list)
Hi,


name pipe wrote:
> Hi,
>
> I would like to know how can we do encryption and decryption using public
> and private keys in ruby. Does ruby any RSA libraries for the same. A small
> example would be quite helpful.
>
> Thanks
>

take a look at the openssl bindings for ruby:

require "openssl"
include OpenSSL
include X509
include PKey

cert = Certificate.new(File.read("server.cer"))
private_key = RSA.new(File.read("server.cer.key"))
message = "This is a test!"

puts("--- Start private key encryption / public key decryption")
crypt = private_key.private_encrypt(message)
puts("Plain text ---------")
puts(message)
puts("Encrypted text------")
puts(crypt)
puts("Decryted text-------")
puts(cert.public_key.public_decrypt(crypt))

puts("--- Start public key encryption / private key decryption")
crypt = cert.public_key.public_encrypt(message)
puts("Encrypted text------")
puts(crypt)
puts("Decryted text-------")
puts(private_key.private_decrypt(crypt))



Regards,
Roland
B31966e5b7926566eb11c2ea96fc1c3d?d=identicon&s=25 name pipe (Guest)
on 2006-04-18 11:36
(Received via mailing list)
Thanks,  but its bit confusing with new include files and stuff. Any
simple
eg. which creates RSA public, private keys and encrypts/decrypts data ?
This topic is locked and can not be replied to.