Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

OpenSSL::BN.new

OpenSSL::BN.new(bn) → aBN
OpenSSL::BN.new(integer) → aBN
OpenSSL::BN.new(string, base = 10) → aBN

Construct a new OpenSSL BIGNUM object.

If bn is an Integer or OpenSSL::BN, a new instance of OpenSSL::BN representing the same value is returned. See also Integer#to_bn for the short-hand.

If a String is given, the content will be parsed according to base.

string

The string to be parsed.

base

The format. Must be one of the following:

  • 0 - MPI format. See the man page BN_mpi2bn(3) for details.

  • 2 - Variable-length and big-endian binary encoding of a positive number.

  • 10 - Decimal number representation, with a leading ‘-’ for a negative number.

  • 16 - Hexadeciaml number representation, with a leading ‘-’ for a negative number.

See also .generate_prime .rand .rand_range also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0