Method: OpenSSL::PKey::DH#compute_key

Defined in:
lib/openssl/pkey.rb

#compute_key(pub_bn) ⇒ Object

:call-seq:

dh.compute_key(pub_bn) -> string

Returns a String containing a shared secret computed from the other party’s public value.

This method is provided for backwards compatibility, and calls #derive internally.

Parameters

  • pub_bn is a OpenSSL::BN, not the DH instance returned by DH#public_key as that contains the DH parameters only.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/openssl/pkey.rb', line 49

def compute_key(pub_bn)
  # FIXME: This is constructing an X.509 SubjectPublicKeyInfo and is very
  # inefficient
  obj = OpenSSL::ASN1.Sequence([
    OpenSSL::ASN1.Sequence([
      OpenSSL::ASN1.ObjectId("dhKeyAgreement"),
      OpenSSL::ASN1.Sequence([
        OpenSSL::ASN1.Integer(p),
        OpenSSL::ASN1.Integer(g),
      ]),
    ]),
    OpenSSL::ASN1.BitString(OpenSSL::ASN1.Integer(pub_bn).to_der),
  ])
  derive(OpenSSL::PKey.read(obj.to_der))
end