解析在RSACryptoServiceProvider.ImportParameters错误与零字节级preFIX消除? [英] Parsing bug in RSACryptoServiceProvider.ImportParameters with zero-byte-prefix elimination?

查看:1644
本文介绍了解析在RSACryptoServiceProvider.ImportParameters错误与零字节级preFIX消除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一些问题,其中使用Security.Cryptography.RSAParameters是用<一个唯一的工作大部分时间创建RSA密钥href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.rsacryptoserviceprovider.aspx"相对=nofollow>的RSACryptoServiceProvider 。<一个href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.rsacryptoserviceprovider.importparameters.aspx"相对=nofollow> 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).

这篇关于解析在RSACryptoServiceProvider.ImportParameters错误与零字节级preFIX消除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆