End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
OpenSSL::PKey::DH.generate
DH.generate(size [, generator]) → dh
ext/openssl/ossl_pkey_dh.c
View on GitHub ↗
static VALUE
ossl_dh_s_generate(int argc, VALUE *argv, VALUE klass)
{
DH *dh ;
int g = 2;
VALUE size, gen, obj;
if (rb_scan_args(argc, argv, "11", &size, &gen) == 2) {
g = NUM2INT(gen);
}
dh = dh_generate(NUM2INT(size), g);
obj = dh_instance(klass, dh);
if (obj == Qfalse) {
DH_free(dh);
ossl_raise(eDHError, NULL);
}
return obj;
}
Creates a new DH instance from scratch by generating the private and public components alike.
Parameters
-
size is an integer representing the desired key size. Keys smaller than 1024 bits should be considered insecure.
-
generator is a small number > 1, typically 2 or 5.