data Crypto::RSA::PublicKey(der: Bytes)

An RSA public key.

pem = File.read("std/test/fixtures/crypto/rsa2048_spki.pem")
pub = Crypto::RSA::PublicKey.from_pem(pem)
pub.bits                  # => 2048
pub.fingerprint.size      # => 32

<std:crypto>:367

Class methods

def self.new(der: Bytes) -> Crypto::RSA::PublicKey

Raises Crypto::Error when der is not an RSA public key (SPKI or PKCS#1); it is kept as SPKI.

<std:crypto>:373

def self.from_pem(pem: String | Bytes) -> Crypto::RSA::PublicKey

The key in pem: one SPKI (PUBLIC KEY) or PKCS#1 (RSA PUBLIC KEY) block.

<std:crypto>:379

def self.from_der(der: Bytes) -> Crypto::RSA::PublicKey

The key in der: SPKI or PKCS#1.

<std:crypto>:384

Methods

def der -> Bytes

The key as SPKI DER, whatever it was read from.

<std:crypto>:369

def to_h -> Hash[Symbol, Object]

The fields as a Hash, by name.

<std:crypto>:373

def with(*, der: Bytes = …) -> Crypto::RSA::PublicKey

A copy with the fields given replaced.

<std:crypto>:373

def to_der -> Bytes

The key as DER: SPKI.

<std:crypto>:387

def to_pem -> String

The key as PEM: SPKI (PUBLIC KEY).

<std:crypto>:390

def bits -> Int

The modulus's size in bits.

<std:crypto>:393

def verify(data: Bytes | String, signature: Bytes, hash: Symbol) -> Bool

Whether signature is the RSASSA-PKCS1-v1_5 signature of data with hash: false for any wrong signature, never an exception.

<std:crypto>:397

def verify_pss(data: Bytes | String, signature: Bytes, hash: Symbol) -> Bool

Whether signature is the RSASSA-PSS signature of data with hash (MGF1 with the same hash), whatever the salt's length: it is read from the signature, as OpenSSL's saltlen:auto and Go's PSSSaltLengthAuto verify. False for any wrong signature.

<std:crypto>:403

def fingerprint -> Bytes

The SHA-256 of the SPKI DER: a key's identity, for key ids and pinning.

<std:crypto>:407

def inspect -> String

#<Crypto::RSA::PublicKey 2048 bits, fingerprint ab12cd34…>.

<std:crypto>:410

def to_s -> String

#<Crypto::RSA::PublicKey 2048 bits, fingerprint ab12cd34…>.

<std:crypto>:416