开发者

Generating Large Prime Numbers for Diffie-Hellman in Ruby

开发者 https://www.devze.com 2023-01-17 19:52 出处:网络
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

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开发者_如何学Python would you recommend?


Use the openssl gem

OpenSSL::BN::rand

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


OpenSSL::BN::generate_prime(500) will do it, like abdollar said. Make sure to put require 'openssl' at the top to include it in your ruby file

To check it is the correct number of bits you can print out the binary by just running OpenSSL::BN::generate_prime(500).to_i.to_s(2).length and it will print out 500, and the leading bit will be a 1

Open SSL Documentation

0

精彩评论

暂无评论...
验证码 换一张
取 消