End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
OpenSSL::PKey::DH#compute_key
dh.compute_key(pub_bn) → string
ext/openssl/lib/openssl/pkey.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.2.0/ext/openssl/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
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 theDHinstance returned byDH#public_keyas that contains theDHparameters only.