[.NET] - 在Create一个RSA密钥的是要注意的长度问题

有时候我们需要自己手动的创建RSA密钥,但是在密钥创建之后,在使用的时候会有类似密钥长度不正确的错误信息被抛出,那可能就是在创建一个RSA密钥的时候,对于的elements长度没设置正确,所以的elements长度要求可以在这里找到:

http://msdn.microsoft.com/en-us/library/cc250013.aspx

    Type (1 byte):  Length MUST be 1 byte.

    This field MUST be set to 0x07.

Version (1 byte):  Length MUST be 1 byte.

This field MUST be set to 0x02.

Reserved (2 bytes):  Length MUST be 2 bytes.

This field MUST be set to 0 and ignored upon receipt.

Key Alg (4 bytes):  Length MUST be 4 bytes.

This field MUST be present as an unsigned integer in little-endian format.

Value MUST be 0x0000A400 (RSA_KEYX).

Magic (4 bytes):  Length MUST be 4 bytes.

This field MUST be present as an unsigned integer in little-endian format.

Value MUST be 0x32415352 (RSA2).

Bitlen (4 bytes):  Length MUST be 4 bytes.

This field MUST be present as an unsigned integer in little-endian format.

The value of this field MUST indicate the number of bits in the (Rivest-Shamir-Adleman) RSA modules. (This is the RSA key size.)

PubExp (4 bytes):  Length MUST be 4 bytes.

This field MUST be present as an unsigned integer in little-endian format.

The value of this field MUST be the RSA public key exponent for this key. The client SHOULD set this value to 65,537.

Modulus (variable):  This field MUST be of length ceil(bl/8), where bl is the value of the Bitlen field defined in the preceding diagram.

This field MUST be present as a byte string in little-endian format.

The value MUST be the RSA key modulus. The modulus is defined as p*q.

P (variable):  This field MUST be of length ceil(bl/16), where bl is the value of the Bitlen field defined in the preceding diagram.

This field MUST be present as a byte string in little-endian format.

The value contained in this field MUST be one of the prime number factors of the modulus (given in the previous field).

Q (variable):  This field MUST be of length ceil(bl/16), where bl is the value of the Bitlen field defined in the preceding diagram.

This field MUST be present as a byte string in little-endian format.

The value MUST be the other prime number factor of the RSA modulus.

Dp (variable):  This field MUST be of length ceil(bl/16), where bl is the value of the Bitlen field defined in the preceding diagram.

This field MUST be present as a byte string in little-endian format.

The value of this field MUST be d mod (p-1), where d is the private exponent of this RSA private key.

Dq (variable):  This field MUST be of length ceil(bl/16), where bl is the value of the Bitlen field defined in the preceding diagram.

This field MUST be present as a byte string in little-endian format.

The value of this field MUST be d mod (q-1), where d is the private exponent of this RSA private key.

Iq (variable):  This field MUST be of length ceil(bl/16), where bl is the value of the Bitlen field defined in the preceding diagram.

This field MUST be present as a byte string in little-endian format.

This field MUST contain the inverse of q modulus p.

D (variable):  This field MUST be of length ceil(bl/8), where bl is the value of the Bitlen field defined in the preceding diagram.

This field MUST be present as a byte string in little-endian format.

The value in this field is the RSA private exponent.

Note  Ceil(x) is the value of x rounded up to the closest integer. For example, ceil(1.2) = 2 and ceil(3) = 3

 

转载于:https://www.cnblogs.com/fred-bao/p/4399186.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值