Sample code for 30+ languages & platforms
Ruby

RSA Import Public Key from Certificate PEM

See more RSA Examples

Uses a certificate's public key for RSA encryption. The public key from the certificate .pem file is used.

Chilkat Ruby Downloads

Ruby
require 'chilkat'

success = false

cert = Chilkat::CkCert.new()

success = cert.LoadFromFile("qa_data/pem/mf_public_rsa.pem")
if (success == false)
    print cert.lastErrorText() + "\n";
    exit
end

pubKey = Chilkat::CkPublicKey.new()
cert.GetPublicKey(pubKey)

rsa = Chilkat::CkRsa.new()
rsa.UsePublicKey(pubKey)

rsa.put_EncodingMode("base64")
encryptedStr = rsa.encryptStringENC("hello",false)
print "encrypted string = " + encryptedStr + "\n";