在 Ruby 中为 Diffie-Hellman 生成大素数

发布于 2024-09-25 11:22:15 字数 120 浏览 2 评论 0原文

我正在用 ruby​​ 为我的大学课程的一个项目编写 diffie-hellman 密钥交换的实现。我需要生成至少 500 位长度的大(安全)素数。有什么想法吗?我应该使用 OpenSSL 库吗?如果是这样,您会推荐哪些功能?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

荒岛晴空 2024-10-02 11:22:15

使用 openssl gem

OpenSSL::BN::rand

您可以指定所需的大小 - 就像这样 OpenSSL::BN::rand(212)

Use the openssl gem

OpenSSL::BN::rand

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

め七分饶幸 2024-10-02 11:22:15

OpenSSL::BN::generate_prime(500) 会做到这一点,就像 abdollar 所说的那样。
确保将 require 'openssl' 放在顶部,将其包含在您的 ruby​​ 文件中

要检查它的位数是否正确,您可以通过运行 OpenSSL::BN 打印出二进制文件::generate_prime(500).to_i.to_s(2).length 它将打印出 500,前导位将是 1

打开 SSL 文档

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文