Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

OpenSSL::PKey::RSA#sign_pss

rsa.sign_pss(digest, data, salt_length:, mgf1_hash:) → String

Signs data using the Probabilistic Signature Scheme (RSA-PSS) and returns the calculated signature.

RSAError will be raised if an error occurs.

See verify_pss for the verification operation.

Parameters

digest

A String containing the message digest algorithm name.

data

A String. The data to be signed.

salt_length

The length in octets of the salt. Two special values are reserved: :digest means the digest length, and :max means the maximum possible length for the combination of the private key and the selected message digest algorithm.

mgf1_hash

The hash algorithm used in MGF1 (the currently supported mask generation function (MGF)).

Example

Example
data = "Sign me!"
pkey = OpenSSL::PKey::RSA.new(2048)
signature = pkey.sign_pss("SHA256", data, salt_length: :max, mgf1_hash: "SHA256")
pub_key = OpenSSL::PKey.read(pkey.public_to_der)
puts pub_key.verify_pss("SHA256", signature, data,
                        salt_length: :auto, mgf1_hash: "SHA256") # => true
See also #set_key #to_der #set_factors #to_pem also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0