Type:
Class

An implementation of the Diffie-Hellman key exchange protocol based on discrete logarithms in finite fields, the same basis that DSA is built on.

Accessor methods for the Diffie-Hellman parameters

  • DH#p

The prime (an OpenSSL::BN) of the Diffie-Hellman parameters.

  • DH#g

The generator (an OpenSSL::BN) g of the Diffie-Hellman parameters.

  • DH#pub_key

The per-session public key (an OpenSSL::BN) matching the private key. This needs to be passed to #compute_key.

  • DH#priv_key

The per-session private key, an OpenSSL::BN.

Example of a key exchange

1
2
3
4
5
6
7
8
dh1 = OpenSSL::PKey::DH.new(2048)
der = dh1.public_key.to_der #you may send this publicly to the participating party
dh2 = OpenSSL::PKey::DH.new(der)
dh2.generate_key! #generate the per-session key pair
symm_key1 = dh1.compute_key(dh2.pub_key)
symm_key2 = dh2.compute_key(dh1.pub_key)
 
puts symm_key1 == symm_key2 # => true
private?
  • References/Ruby on Rails/Ruby/Classes/OpenSSL/OpenSSL::PKey/OpenSSL::PKey::DH

dh.private? â true | false Instance Public methods Indicates whether this

2025-01-10 15:47:30
generate
  • References/Ruby on Rails/Ruby/Classes/OpenSSL/OpenSSL::PKey/OpenSSL::PKey::DH

DH.generate(size [, generator]) â dh Class Public methods Creates a new

2025-01-10 15:47:30
to_s
  • References/Ruby on Rails/Ruby/Classes/OpenSSL/OpenSSL::PKey/OpenSSL::PKey::DH

to_s() Instance Public methods Alias for:

2025-01-10 15:47:30
public?
  • References/Ruby on Rails/Ruby/Classes/OpenSSL/OpenSSL::PKey/OpenSSL::PKey::DH

dh.public? â true | false Instance Public methods Indicates whether this

2025-01-10 15:47:30
to_pem
  • References/Ruby on Rails/Ruby/Classes/OpenSSL/OpenSSL::PKey/OpenSSL::PKey::DH

to_pem() Instance Public methods Alias for:

2025-01-10 15:47:30
compute_key
  • References/Ruby on Rails/Ruby/Classes/OpenSSL/OpenSSL::PKey/OpenSSL::PKey::DH

dh.compute_key(pub_bn) â aString Instance Public methods Returns a String containing

2025-01-10 15:47:30
new
  • References/Ruby on Rails/Ruby/Classes/OpenSSL/OpenSSL::PKey/OpenSSL::PKey::DH

DH.new([size [, generator] | string]) â dh Class Public methods Either generates

2025-01-10 15:47:30
export
  • References/Ruby on Rails/Ruby/Classes/OpenSSL/OpenSSL::PKey/OpenSSL::PKey::DH

dh.to_pem â aString Instance Public methods Encodes this

2025-01-10 15:47:30
to_der
  • References/Ruby on Rails/Ruby/Classes/OpenSSL/OpenSSL::PKey/OpenSSL::PKey::DH

dh.to_der â aString Instance Public methods Encodes this

2025-01-10 15:47:30
public_key
  • References/Ruby on Rails/Ruby/Classes/OpenSSL/OpenSSL::PKey/OpenSSL::PKey::DH

dh.public_key â aDH Instance Public methods Returns a new

2025-01-10 15:47:30