c# - C#生成RSA私钥

标签 c# encryption cryptography rsa

我有 pqne 的值,我想计算私有(private)键 d。我该怎么做,有人可以给我示例 C# 代码吗?我正在使用 BigInteger 类来表示 pqne< 的值 所以我假设 d 也是一个 BigInteger

最佳答案

来自 Wikipedia :

Determine d (using modular arithmetic) which satisfies the congruence relation alt text

  • Stated differently, ed − 1 can be evenly divided by the totient (p − 1)(q − 1).
  • This is often computed using the extended Euclidean algorithm.
  • d is kept as the private key exponent.

扩展欧几里德算法允许您找到满足以下条件的整数:

alt text

The extended Euclidean algorithm is particularly useful when a and b are coprime, since x is the modular multiplicative inverse of a modulo b.

在此公式中,将 a 设置为 e,将 b 设置为 (p-1)(q-1)gcd(a, b) 到 1(因为在 RSA 算法中要求 e 和 φ(pq) 互质)并求解 x 这给了你dextended Euclidean algorithm 上的维基百科页面有关如何编写求解 x 和 y 的算法的更多详细信息。例如,您可以使用这个递归函数(在伪代码中):

function extended_gcd(a, b)
    if a mod b = 0
        return {0, 1}
    else
        {x, y} := extended_gcd(b, a mod b)
        return {y, x-(y*(a div b))}

在 .NET 中,如果您只想生成一些 RSA key ,则不必自己实现 RSA 算法。您可以使用 .NET 框架中的 RSA 实现。

关于c# - C#生成RSA私钥,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3740874/

相关文章:

c# - 如何在 Microsoft Graph 中使用 DI

php - c++中的加密和php中的解密有什么问题

php - 如何使用 php 和 mysql 处理加密的私有(private)消息

c# - Dapper Reader 处置异常

c# - 在 SqlBulkCopy 期间更改值

java - 在 JSF 中读取和显示加密的 PDF 文件

linux - 如何判断附加到 Azure 虚拟机的磁盘是否已加密?

algorithm - 特定算法如何解密?

hash - 在 erlang 中计算 MD5 哈希值

C# 应用程序应该是异步的,但 UI 仍然卡住