123456789_123456789_123456789_123456789_123456789_

Class: OpenSSL::PKey::RSA

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, PKey
Instance Chain:
self, PKey
Inherits: OpenSSL::PKey::PKey
Defined in: ext/openssl/ossl_pkey_rsa.c

Overview

RSA is an asymmetric public key algorithm that has been formalized in RFC 3447. It is in widespread use in public key infrastructures (PKI) where certificates (cf. ::OpenSSL::X509::Certificate) often are issued on the basis of a public/private RSA key pair. RSA is used in a wide field of applications such as secure (symmetric) key exchange, e.g. when establishing a secure TLS/SSL connection. It is also used in various digital signature schemes.

Class Method Summary

PKey - Inherited

.new

Because PKey is an abstract class, actually calling this method explicitly will raise a NotImplementedError.

Instance Attribute Summary

Instance Method Summary

PKey - Inherited

#sign

To sign the String data, digest, an instance of ::OpenSSL::Digest, must be provided.

#verify

To verify the String signature, digest, an instance of ::OpenSSL::Digest, must be provided to re-compute the message digest of the original data, also a String.

Constructor Details

.new(key_size) ⇒ RSA .new(encoded_key) ⇒ RSA .new(encoded_key, pass_phrase) ⇒ RSA

Generates or loads an RSA keypair. If an integer key_size is given it represents the desired key size. Keys less than 1024 bits should be considered insecure.

A key can instead be loaded from an encoded_key which must be PEM or DER encoded. A pass_phrase can be used to decrypt the key. If none is given ::OpenSSL will prompt for the pass phrase.

Examples

OpenSSL::PKey::RSA.new 2048
OpenSSL::PKey::RSA.new File.read 'rsa.pem'
OpenSSL::PKey::RSA.new File.read('rsa.pem'), 'my pass phrase'

Class Method Details

.generate(size) ⇒ RSA .generate(size, exponent) ⇒ RSA

Generates an RSA keypair. size is an integer representing the desired key size. Keys smaller than 1024 should be considered insecure. exponent is an odd number normally 3, 17, or 65537.

Instance Attribute Details

#private?Boolean (readonly)

Does this keypair contain a private key?

#public?Boolean (readonly)

The return value is always true since every private key is also a public key.

Instance Method Details

#export([cipher, pass_phrase]) ⇒ PEM-format String #to_pem([cipher, pass_phrase]) ⇒ PEM-format String #to_s([cipher, pass_phrase]) ⇒ PEM-format String

Alias for #to_s.

#paramsHash

THIS METHOD IS INSECURE, PRIVATE INFORMATION CAN LEAK OUT!!!

Stores all parameters of key to the hash. The hash has keys 'n', 'e', 'd', 'p', 'q', 'dmp1', 'dmq1', 'iqmp'.

Don't use :-)) (It's up to you)

#private_decrypt(string) ⇒ String #private_decrypt(string, padding) ⇒ String

Decrypt string, which has been encrypted with the public key, with the private key. padding defaults to PKCS1_PADDING.

#private_encrypt(string) ⇒ String #private_encrypt(string, padding) ⇒ String

Encrypt string with the private key. padding defaults to PKCS1_PADDING. The encrypted string output can be decrypted using #public_decrypt.

#public_decrypt(string) ⇒ String #public_decrypt(string, padding) ⇒ String

Decrypt string, which has been encrypted with the private key, with the public key. padding defaults to PKCS1_PADDING.

#public_encrypt(string) ⇒ String #public_encrypt(string, padding) ⇒ String

Encrypt string with the public key. padding defaults to PKCS1_PADDING. The encrypted string output can be decrypted using #private_decrypt.

#public_keyRSA

Makes new RSA instance containing the public key from the private key.

#set_crt_params(dmp1, dmq1, iqmp) ⇒ self

Sets dmp1, dmq1, iqmp for the RSA instance. They are calculated by d mod (p - 1), d mod (q - 1) and q^(-1) mod p respectively.

#set_factors(p, q) ⇒ self

Sets p, q for the RSA instance.

#set_key(n, e, d) ⇒ self

Sets n, e, d for the RSA instance.

#to_derDER-format String

Outputs this keypair in DER encoding.

#export([cipher, pass_phrase]) ⇒ PEM-format String #to_pem([cipher, pass_phrase]) ⇒ PEM-format String #to_s([cipher, pass_phrase]) ⇒ PEM-format String

Alias for #to_s.

#export([cipher, pass_phrase]) ⇒ PEM-format String #to_pem([cipher, pass_phrase]) ⇒ PEM-format String #to_s([cipher, pass_phrase]) ⇒ PEM-format String
Also known as: #export, #to_pem

Outputs this keypair in PEM encoding. If cipher and pass_phrase are given they will be used to encrypt the key. cipher must be an ::OpenSSL::Cipher instance.

#to_textString

THIS METHOD IS INSECURE, PRIVATE INFORMATION CAN LEAK OUT!!!

Dumps all parameters of a keypair to a String

Don't use :-)) (It's up to you)