Search code examples
rubycryptographydiffie-hellman

Generating Large Prime Numbers for Diffie-Hellman in Ruby


I'm writing an implementation of a diffie-hellman key exchange in ruby for a project for one of my university classes. I need to generate large (secure) prime numbers of at least 500 bits length. Any ideas? Should I use the OpenSSL library? If so, what functions would you recommend?


Solution

  • Use the openssl gem

    OpenSSL::BN::rand

    You can specify the size you need - like so OpenSSL::BN::rand(212)