解析在RSACryptoServiceProvider.ImportParameters错误与零字节级preFIX消除?字节、错误、RSACryptoServiceProvider、ImportPar

由网友(旧梦悠悠苦我心°)分享简介:我遇到了一些问题,其中使用Security.Cryptography.RSAParameters是用的RSACryptoServiceProvider 。 ImportParameters 的。I had some problems where RSA keys created using the Security....

我遇到了一些问题,其中使用Security.Cryptography.RSAParameters是用的RSACryptoServiceProvider 。 ImportParameters 的。

I had some problems where RSA keys created using the Security.Cryptography.RSAParameters were working only most of the time with RSACryptoServiceProvider.ImportParameters.

在一堆调试它的看来,该对象的属性,要非常具体的字节的缓冲区大小。我的ASN.1语法分析code的零字节级preFIX消除。事实上,RSAParameters的某些字段只有在零字节级preFIX淘汰工作,并在所有如果零字节级preFIX消除已经做了别人不工作。

After a bunch of debugging it appears that the properties of that object want very specific byte buffer sizes. My ASN.1 parsing code has zero-byte-prefix elimination. In fact, some fields of the RSAParameters only work after zero-byte-prefix elimination and others don't work at all if zero-byte-prefix elimination has been done.

参数几乎每隔一段时间,一个确实有更多的前导零由于正常的随机化,造成所得键无法正常工作。

Every so often one of the parameters does have more leading zeros due to normal randomization and caused the resulting key to not work properly.

这是一些被认为是一个错误?

Is this something that is considered a bug?

推荐答案

.NET要求每个RSA参数的大小是一个准确的大小(WRT密钥对大小)。

.NET requires the size of each RSA parameters to be of an exact size (wrt key pair size).

所以有时你需要删除前导0×00字节(例如,如果数据来自ASN.1这需要一个0领先为正数)。

So sometimes you'll need to remove the leading 0x00 byte (e.g. if the data comes from ASN.1 which requires a leading 0 for positive numbers).

但其他时候,你需要添加一个额外的0×00字节,因为字节重新present可能适合较少字节(1现实中)一个(巨大)的数量。这从PEM(BASE64)分析数据时,连接的地方领导0通常会删除codeD文件时出现。

But other times you need to add an extra 0x00 byte because the bytes represent a (huge) number that might fit with fewer bytes (1 in reality). This occurs when parsing data from PEM (base64) encoded files where the leading 0 is generally removed.

最后的答案:确保您提供的预期长度(垫或删除填充)

Final answer: ensure you're provided the expected length (pad or remove padding).

阅读全文

相关推荐

最新文章