Ruby 2.5.0 リファレンスマニュアル > ライブラリ一覧 > opensslライブラリ > 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 についてよく理解し、必要な場合のみにすべきです。
例:
require 'openssl' # 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.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")
定義 | 説明 | |
---|---|---|
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__
instance_eval
instance_exec
method_missing
singleton_method_added
singleton_method_removed
singleton_method_undefined
!~
<=>
==
===
=~
_dump
class
clone
define_singleton_method
display
enum_for
eql?
equal?
extend
freeze
frozen?
hash
initialize
initialize_copy
inspect
instance_of?
instance_variable_defined?
instance_variable_get
instance_variable_set
instance_variables
is_a?
itself
marshal_dump
marshal_load
method
methods
nil?
object_id
pretty_inspect
pretty_print
pretty_print_cycle
pretty_print_inspect
pretty_print_instance_variables
private_methods
protected_methods
psych_to_yaml
public_method
public_methods
public_send
remove_instance_variable
respond_to?
respond_to_missing?
send
singleton_class
singleton_method
singleton_methods
taint
tainted?
tap
to_a
to_ary
to_hash
to_int
to_io
to_proc
to_regexp
to_str
trust
untaint
untrust
untrusted?
yield_self
.yaml_tag
::ARGF
::ARGV
::DATA
::ENV
::FALSE
::NIL
::RUBY_COPYRIGHT
::RUBY_DESCRIPTION
::RUBY_ENGINE
::RUBY_ENGINE_VERSION
::RUBY_PATCHLEVEL
::RUBY_PLATFORM
::RUBY_RELEASE_DATE
::RUBY_REVISION
::RUBY_VERSION
::SCRIPT_LINES__
::STDERR
::STDIN
::STDOUT
::TOPLEVEL_BINDING
::TRUE
sign
verify