RSAParameters 结构


表示 RSA 算法的标准参数。Represents the standard parameters for the RSA algorithm.

public value class RSAParameters
public struct RSAParameters
public struct RSAParameters
public struct RSAParameters
type RSAParameters = struct
Public Structure RSAParameters


RSA 类公开了一种 ExportParameters 方法,该方法使你能够以 RSAParameters 结构的形式检索原始 RSA 密钥。The RSA class exposes an ExportParameters method that enables you to retrieve the raw RSA key in the form of an RSAParameters structure. 了解此结构的内容需要熟悉 RSA 算法的工作原理。Understanding the contents of this structure requires familiarity with how the RSA algorithm works. 下一节将简要讨论该算法。The next section discusses the algorithm briefly.

RSA 算法RSA Algorithm

若要生成密钥对,首先要创建两个名为 p 和 q 的大型质数。To generate a key pair, you start by creating two large prime numbers named p and q. 这些数字将相乘,结果称为 n。These numbers are multiplied and the result is called n. 由于 p 和 q 均为质数,因此 n 的唯一因素是1、p、q 和 n。Because p and q are both prime numbers, the only factors of n are 1, p, q, and n.

如果只考虑小于 n 的数字,则相对于 n 的数字的计数(即,没有与 n 相同的因素,等于(p-1)(q-1)。If we consider only numbers that are less than n, the count of numbers that are relatively prime to n, that is, have no factors in common with n, equals (p - 1)(q - 1).

现在,请选择数字 e,这与计算得出的值相对质数。Now you choose a number e, which is relatively prime to the value you calculated. 公钥现在表示为 {e,n}。The public key is now represented as {e, n}.

若要创建私钥,必须计算 d,它是一个数字,因此(d)(e) mod (p-1) = 1。To create the private key, you must calculate d, which is a number such that (d)(e) mod (p - 1)(q - 1) = 1. 根据欧氏算法,私钥现在为 {d,n}。In accordance with the Euclidean algorithm, the private key is now {d, n}.

纯文本 m 到密码文本 c 的加密定义为 c = (m ^ e) mod n。Encryption of plaintext m to ciphertext c is defined as c = (m ^ e) mod n. 解密将被定义为 m = (c ^ d) mod n。Decryption would then be defined as m = (c ^ d) mod n.

字段摘要Summary of Fields

第1.2 部分 PKCS #1: RSA 实验室网站上的Rsa 加密标准为 rsa 私钥定义格式。Section A.1.2 of the PKCS #1: RSA Cryptography Standard on the RSA Laboratories Web site defines a format for RSA private keys.

下表汇总了 RSAParameters 结构的字段。The following table summarizes the fields of the RSAParameters structure. 第三列提供了PKCS #1: RSA 加密标准一节中的相应字段。The third column provides the corresponding field in section A.1.2 of PKCS #1: RSA Cryptography Standard.

RSAParameters 字段RSAParameters field 包含Contains 对应的 PKCS #1 字段Corresponding PKCS #1 field
D d. 专用指数d, the private exponent privateExponentprivateExponent
DP d mod (第1项)d mod (p - 1) exponent1exponent1
DQ d mod (q-1)d mod (q - 1) exponent2exponent2
Exponent e,公共指数e, the public exponent publicExponentpublicExponent
InverseQ (InverseQ)(q) = 1 mod p(InverseQ)(q) = 1 mod p 系数coefficient
Modulus nn modulusmodulus
P pp prime1prime1
Q qq prime2prime2

RSA 的安全性派生于这样一个事实:在给定公钥 {e,n} 的情况下,不能计算 d (直接或通过将 n 分解为 p 和 q)来计算 d。The security of RSA derives from the fact that, given the public key { e, n }, it is computationally infeasible to calculate d, either directly or by factoring n into p and q. 因此,与 d、p 或 q 相关的密钥的任何部分都必须保持机密。Therefore, any part of the key related to d, p, or q must be kept secret. 如果调用If you call

ExportParameters,只要求提供公钥信息,这就是为什么只接收 ExponentModulus的原因。ExportParameters and ask for only the public key information, this is why you will receive only Exponent and Modulus. 仅当你有权访问私钥并请求它时,其他字段才可用。The other fields are available only if you have access to the private key, and you request it.

不会以任何方式对 RSAParameters 进行加密,因此,在将其与私钥信息一起使用时,必须谨慎。RSAParameters is not encrypted in any way, so you must be careful when you use it with the private key information. 事实上,不能序列化包含私钥信息的任何字段。In fact, none of the fields that contain private key information can be serialized. 如果尝试使用远程调用或使用一个序列化程序来序列化 RSAParameters 结构,则只会收到公钥信息。If you try to serialize an RSAParameters structure with a remoting call or by using one of the serializers, you will receive only public key information. 如果要传递私钥信息,则必须手动发送这些数据。If you want to pass private key information, you will have to manually send that data. 在所有情况下,如果任何人都可以派生出参数,则您传输的密钥会毫无用处。In all cases, if anyone can derive the parameters, the key that you transmit becomes useless.

.Net Core 2.1.0 及更高版本:已删除序列化限制,并对 RSAParameters 的所有成员进行序列化。.NET Core 2.1.0 and later: The serialization restrictions have been removed and all members of RSAParameters are serialized. 对 .NET Core 2.1.0 或更高版本的代码进行编写或升级时,必须 excercised,因为如果任何人都可以派生或截取私钥参数,密钥和所有加密或签名的信息都将受到威胁。Care must be excercised when writing or upgrading code against .NET Core 2.1.0 or later, because if anyone can derive or intercept the private key parameters the key and all the information encrypted or signed with it are compromised.



表示 RSA 算法的 D 参数。Represents the D parameter for the RSA algorithm.


表示 RSA 算法的 DP 参数。Represents the DP parameter for the RSA algorithm.


表示 RSA 算法的 DQ 参数。Represents the DQ parameter for the RSA algorithm.


表示 RSA 算法的 Exponent 参数。Represents the Exponent parameter for the RSA algorithm.


表示 RSA 算法的 InverseQ 参数。Represents the InverseQ parameter for the RSA algorithm.


表示 RSA 算法的 Modulus 参数。Represents the Modulus parameter for the RSA algorithm.


表示 RSA 算法的 P 参数。Represents the P parameter for the RSA algorithm.


表示 RSA 算法的 Q 参数。Represents the Q parameter for the RSA algorithm.