instance method
OpenSSL::PKey::DH#public_key
() -> self
dh.public_key → dhnew
ext/openssl/lib/openssl/pkey.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/ext/openssl/lib/openssl/pkey.rb, line 36
def public_key
DH.new(to_der)
end
Returns a new DH instance that carries just the DH parameters.
Contrary to the method name, the returned DH object contains only parameters and not the public key.
This method is provided for backwards compatibility. In most cases, there is no need to call this method.
For the purpose of re-generating the key pair while keeping the parameters, check OpenSSL::PKey.generate_key.
Example:
Example
# OpenSSL::PKey::DH.generate by default generates a random key pair dh1 = OpenSSL::PKey::DH.generate(2048) p dh1.priv_key #=> #<OpenSSL::BN 1288347...> dhcopy = dh1.public_key p dhcopy.priv_key #=> nil