class OpenSSL::PKey::PKey
An abstract class that bundles signature creation (PKey#sign) and validation (PKey#verify) that is common to all implementations except OpenSSL::PKey::DH * OpenSSL::PKey::RSA * OpenSSL::PKey::DSA * OpenSSL::PKey::EC
Public Class Methods
() → void
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/openssl/0/openssl.rbs, line 7174
def initialize: () -> void
Because PKey is an abstract class, actually calling this method explicitly will raise a NotImplementedError.
Public Instance Methods
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/openssl/0/openssl.rbs, line 7031
def inspect: () -> String
Returns a string describing the PKey object.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/openssl/0/openssl.rbs, line 7039
def oid: () -> String
Returns the short name of the OID associated with pkey.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/openssl/0/openssl.rbs, line 7051
def private_to_der: (String cipher, String password) -> String
| () -> String
Serializes the private key to DER-encoded PKCS #8 format. If called without arguments, unencrypted PKCS #8 PrivateKeyInfo format is used. If called with a cipher name and a password, PKCS #8 EncryptedPrivateKeyInfo format with PBES2 encryption scheme is used.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/openssl/0/openssl.rbs, line 7074
def private_to_pem: (String cipher, String password) -> String
| () -> String
Serializes the private key to PEM-encoded PKCS #8 format. See private_to_der for more details.
An unencrypted PEM-encoded key will look like:
-----BEGIN PRIVATE KEY----- [...] -----END PRIVATE KEY-----
An encrypted PEM-encoded key will look like:
-----BEGIN ENCRYPTED PRIVATE KEY----- [...] -----END ENCRYPTED PRIVATE KEY-----
() → String
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/openssl/0/openssl.rbs, line 7083
def public_to_der: () -> String
Serializes the public key to DER-encoded X.509 SubjectPublicKeyInfo format.
() → String
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/openssl/0/openssl.rbs, line 7097
def public_to_pem: () -> String
Serializes the public key to PEM-encoded X.509 SubjectPublicKeyInfo format.
A PEM-encoded key will look like:
-----BEGIN PUBLIC KEY----- [...] -----END PUBLIC KEY-----
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/openssl/0/openssl.rbs, line 7135
def sign: (Digest digest, String data) -> String
Hashes and signs the data using a message digest algorithm digest and a private key pkey.
See verify for the verification operation.
See also the man page EVP_DigestSign(3).
digest-
A
Stringthat represents the message digest algorithm name, ornilif thePKeytype requires no digest algorithm. For backwards compatibility, this can be an instance ofOpenSSL::Digest. Its state will not affect the signature. data-
A
String. The data to be hashed and signed. options-
A
Hashthat contains algorithm specific control operations toOpenSSL. See OpenSSL’s man page EVP_PKEY_CTX_ctrl_str(3) for details.optionsparameter was added in version 3.0.
Example: data = “Sign me!” pkey = OpenSSL::PKey.generate_key(“RSA”, rsa_keygen_bits: 2048) signopts = { rsa_padding_mode: “pss” } signature = pkey.sign(“SHA256”, data, signopts)
# Creates a copy of the RSA key pkey, but without the private components pub_key = pkey.public_key puts pub_key.verify("SHA256", signature, data, signopts) # => true
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/openssl/0/openssl.rbs, line 7163
def verify: (Digest digest, String signature, String data) -> bool
Verifies the signature for the data using a message digest algorithm digest and a public key pkey.
Returns true if the signature is successfully verified, false otherwise. The caller must check the return value.
See sign for the signing operation and an example.
See also the man page EVP_DigestVerify(3).