Skip to content
instance method

OpenSSL::PKey::DH#public_key

() -> self
dh.public_key → dhnew

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
See also #public? #set_key #private? #set_pqg also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0