Beryl::Crypto::V1::RivestShamirAdleman::PublicKey
An RSA public key: a modulus of 2,048 to 8,192 bits and an odd public exponent from 3 to 2^32 - 1. It verifies signatures and encrypts.
public_key = Beryl::Crypto::V1::RSA::PublicKey.new(modulus_bytes, 65_537)
public_key.verify_pkcs1_signature(message, signature, hash_function: Beryl::Crypto::V1::SHA256) # => true or false
Everything a public key does is public, so its operations may take time that depends on their inputs.
Constants
Constructors
Takes the big-endian modulus (leading zero bytes allowed) and the
public exponent, as big-endian bytes or as an integer. Raises
KeySizeNotSupported or PublicExponentNotSupported when either is
outside the ranges above, or when the modulus is even.
Instance methods
Returns message encrypted with RSAES-OAEP (RFC 8017 §7.1.1), with
hash_function for the label and for MGF1 (Compatibility::SHA1 or
a SHA-2 hash) and an optional label. Raises
MessageTooLongForModulus when the message is longer than the
modulus size less twice the hash size less 2 bytes.
Returns whether signature is a PKCS #1 v1.5 signature (RFC 8017
§8.2) of message hashed with hash_function: one of
Compatibility::SHA1, SHA224, SHA256, SHA384, SHA512,
SHA512_256. The expected encoding is built and compared whole, so
only the one exact encoding is accepted. Never raises for a malformed
signature.
Returns whether signature is a PSS signature (RFC 8017 §8.1) of message, with hash_function (a SHA-2 hash) for the message and for MGF1, and a salt of salt_bytesize bytes. Never raises for a malformed signature.