Ruby 1.9.2 リファレンスマニュアル > ライブラリ一覧 > opensslライブラリ > OpenSSL::PKey::RSAクラス

class OpenSSL::PKey::RSA

クラスの継承リスト: OpenSSL::PKey::RSA < OpenSSL::PKey::PKey < Object < Kernel < BasicObject

要約

RSA 暗号鍵のクラスです。

通常このクラスで利用するのは、 OpenSSL::PKey::RSA.generate, OpenSSL::PKey::RSA.new, OpenSSL::PKey::RSA#public?, OpenSSL::PKey::RSA#private?, OpenSSL::PKey::RSA#public_key, OpenSSL::PKey::RSA#to_text, OpenSSL::PKey::RSA#to_pem, OpenSSL::PKey::RSA#to_der のいずれかでしょう。これ以外のメソッドを利用するときは RSA についてよく理解し、必要な場合のみにすべきです。

例:

# initialize random seed
OpenSSL::Random.seed(File.read("/dev/random", 16))
# 鍵対を生成
rsa = OpenSSL::PKey::RSA.generate(2048)
# 秘密鍵をAES256で暗号化して private_key.pem に PEM 形式で保存
passphrase = "!secret passphrase!"
File.open("private_key.pem", "w") do |f|
  f.write(rsa.export(OpenSSL::Cipher::Cipher.new("aes256"), passphrase))
end
# 公開鍵をpublic_key.pemに保存
public_key = rsa.public_key
File.open("public_key.pem", "w") do |f|
  f.write(public_key.export)
end

# 秘密鍵で署名
data = "foobar"
sign = rsa.sign("sha256", data)
# 公開鍵で検証
p public_key.verify("sha256", sign, data)
# 不正なデータを検証
p public_key.verify("sha256", sign, "foobarbaz")

特異メソッド

定義 説明
generate(size, exponent = 65537) -> OpenSSL::PKey::RSA
generate(size, exponent = 65537) {|u,n| ... } -> OpenSSL::PKey::RSA

乱数により RSA 公開鍵と秘密鍵のペアを生成して、RSA オブジェクトを返します。

new -> OpenSSL::PKey::RSA
new(size, exponent = 65537) -> OpenSSL::PKey::RSA
new(size, exponent = 65537) {|u,n| ... } -> OpenSSL::PKey::RSA
new(obj, pass = nil) -> OpenSSL::PKey::RSA
new(obj, pass = nil) {|flag| ... } -> OpenSSL::PKey::RSA

RSA 暗号鍵オブジェクトを生成します。

インスタンスメソッド

定義 説明
d -> OpenSSL::BN

鍵の private exponent です。

d=(new_d)

private exponent を設定します。

dmp1 -> OpenSSL::BN

鍵の exponent1 (d mod (p-1)) です。

dmp1=(new_dmp1)

鍵の exponent1 を設定します。

dmq1 -> OpenSSL::BN

鍵の exponent2 (d mod (q-1)) です。

dmq1=(new_dmq1)

鍵の exponent2 を設定します。

e -> OpenSSL::BN

鍵の public exponent を返します。

e=(new_e)

鍵の public exponent を変更します。

export(cipher=nil, pass=nil) -> String
export(cipher=nil, pass=nil) {|flag| ... } -> String
to_pem(cipher=nil, pass=nil) -> String
to_pem(cipher=nil, pass=nil) {|flag| ... } -> String
to_s(cipher=nil, pass=nil) -> String
to_s(cipher=nil, pass=nil) {|flag| ... } -> String

鍵を PEM 形式で出力します。

iqmp -> OpenSSL::BN

鍵の coefficient (inverse of q mod p) です。

iqmp=(new_iqmp)

鍵の coefficient を設定します。

n -> OpenSSL::BN

鍵の modulus です。

n=(new_n)

鍵の modules を設定します。

p -> OpenSSL::BN

鍵の1つめの素数です。

p=(new_p)

鍵の1つめの素数を設定します。

params -> {String => OpenSSL::BN}

鍵のパラメータ([[OpenSSL::PKey::RSA#e]],[[OpenSSL::PKey::RSA#n]], [[OpenSSL::PKey::RSA#d]]など)を{パラメータ名文字列 => パラメータ値} というハッシュで返します。

private? -> bool

自身が秘密鍵を持っているかどうか判定します。

private_decrypt(str, mode = OpenSSL::PKey::RSA::PKCS1_PADDING) -> String

文字列 str を秘密鍵で復号化します。

private_encrypt(str, mode = OpenSSL::PKey::RSA::PKCS1_PADDING) -> String

文字列 str を秘密鍵で暗号化します。

public? -> bool

自身が公開鍵を持っているかどうか判定します。

public_decrypt(str, mode = OpenSSL::PKey::RSA::PKCS1_PADDING) -> String

文字列 str を公開鍵で復号化します。

public_encrypt(str, mode = OpenSSL::PKey::RSA::PKCS1_PADDING) -> String

文字列 str を公開鍵で暗号化します。

public_key -> OpenSSL::PKey::RSA

公開鍵を複製して RSA オブジェクトとして返します。

q -> OpenSSL::BN

鍵の2つめの素数です。

q=(new_q)

鍵の2つめの素数を設定します。

to_der -> String

自身を DER 形式に変換します。

to_text -> String

鍵を人間が読める形式に変換します。

定数

定義 説明
NO_PADDING -> Integer

パディングをしないパディングモードです。

PKCS1_OAEP_PADDING -> Integer

PKCS #1 v2.0 で定義されているパディングモードです。

PKCS1_PADDING -> Integer

PKCS #1 v1.5 で定義されているパディングモードです。

SSLV23_PADDING -> Integer

PKCS #1 v1.5 で定義されているものに SSL特有の変更を加えたパディングモードです。

継承したメソッド

! != == === =~ __id__ __send__ _dump class clone dclone display enum_for eql? equal? extend freeze frozen? hash initialize initialize_copy inspect instance_eval instance_exec instance_of? instance_variable_defined? instance_variable_get instance_variable_set instance_variables is_a? marshal_dump marshal_load method method_missing methods must_be must_be_close_to must_be_empty must_be_instance_of must_be_kind_of must_be_nil must_be_same_as must_be_within_epsilon must_equal must_include must_match must_raise must_respond_to must_send must_throw nil? pretty_inspect pretty_print pretty_print_cycle pretty_print_inspect pretty_print_instance_variables private_methods protected_methods public_methods remove_instance_variable respond_to? respond_to_missing? singleton_class singleton_method_added singleton_method_removed singleton_method_undefined singleton_methods taint tainted? tap to_a to_ary to_hash to_int to_io to_proc to_regexp to_str to_yaml to_yaml_properties to_yaml_style trust untaint untrust untrusted? wont_be wont_be_close_to wont_be_empty wont_be_instance_of wont_be_kind_of wont_be_nil wont_be_same_as wont_be_within_epsilon wont_equal wont_include wont_match wont_respond_to sign verify