Method: OpenSSL::PKey::DH#public_key

Defined in:
lib/openssl/pkey.rb

#public_keyObject

:call-seq:

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:

# 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


33
34
35
# File 'lib/openssl/pkey.rb', line 33

def public_key
  DH.new(to_der)
end