C#中签名程序集的公钥的结构是什么?
使用此代码检索公钥字节C#中签名程序集的公钥的结构是什么?,c#,.net-assembly,public-key,modulus,exponent,C#,.net Assembly,Public Key,Modulus,Exponent,使用此代码检索公钥字节 var pubKey = AppDomain.CurrentDomain.DomainManager.EntryAssembly .GetName().GetPublicKey(); 密钥开头(前32个字节)的公共结构是什么? 它不是ASN.1,也可能不是可变的。我可以在谷歌上搜索并获得重复 // 00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 00 24 00 00 52 53 41 31 是
var pubKey =
AppDomain.CurrentDomain.DomainManager.EntryAssembly
.GetName().GetPublicKey();
密钥开头(前32个字节)的公共结构是什么?
它不是ASN.1,也可能不是可变的。我可以在谷歌上搜索并获得重复
// 00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 00 24 00 00 52 53 41 31
是否全部颠倒或只是其一部分(例如,末端的模量)52 53 41 31
是一个由RSA1
组成的字符串。
我的键的模数是1024位,所以我在寻找描述长度的东西。
0x0400
(0004
B.E.)将为1024(位),0x80
将为128(字节,1024/8)
最后4到6个是公众指数吗?大端还是小端?最后一个空值是终止符还是间隔符
对RSAPKCS1SignatureFormatter
和RSAPKCS1SignatureFormatter
的实现(.NET和Mono)进行调查并不容易
删除编辑,回答自己的问题。。。除非有人能给出更好的答案或添加详细信息,包括原因。我忍不住咬指甲,试图从CALG_RSA_SIGN=0x00002400开始反向工作,然后偶然发现RSAPUBKEY,然后是publickeystrac,最后是PublicKeyBlob。 现在我可以正式解析它了。 想知道在.NET framework中是否已经有任何结构来处理此问题 哦,嘿,这些神奇的数字看起来很熟悉。它们是什么意思 是吗 因此,使用此信息(无法使rsaCsp.ImportParameters正常工作)
var rsaCsp=新的rsaccryptoserviceprovider(位长度);
rsaCsp.FromXmlString(string.Format(
"{1}{0}",
Convert.ToBase64String(PubExp),Convert.ToBase64String(PubMod));
现在,您已经从程序集的SN PK获得了用于签名身份验证的有效rsaCsp。还有一个警告。。。必须将PubExp转换为字节,并去除前导零字节(修剪高0字节,例如01 00 01 00->01 00 01->AQAB,而不是AQABAA==)。
// 00 04 00 00 01 00 01 00
// 00 24 00 00 // 0x00002400 LE // PublicKeyBlob SigAlgId ALG_ID = CALG_RSA_SIGN
// 04 80 00 00 // 0x00008004 LE // PublicKeyBlob HashAlgId ALG_ID = CALG_SHA1
// 94 00 00 00 // 0x00000094 LE // PublicKeyBlob cbPublicKey dword = 148
// sizeof(PUBLICKEYSTRUC) is 8 + sizeof(RSAPUBKEY) is 12 + sizeof(modulus) is 128 = 148
// 06 // 0x06 // PUBLICKEYSTRUC bType byte = PUBLICKEYBLOB
// 02 // 0x02 // PUBLICKEYSTRUC bVersion byte = CUR_BLOB_VERSION
// 00 00 // 0x0000 LE // PUBLICKEYSTRUC reserved word = 0
// 00 24 00 00 // 0x00002400 LE // PUBLICKEYSTRUC aiKeyAlg ALG_ID = CALG_RSA_SIGN
// 52 53 41 31 // 'RSA1' // RSAPUBKEY magic dword
// 00 04 00 00 // 0x00000400 LE // RSAPUBKEY bitlen dword
// 01 00 01 00 // 0x00010001 LE // RSAPUBKEY pubexp dword
// public modulus reversed follows in (bitlen/8) bytes
var rsaCsp = new RSACryptoServiceProvider(BitLength);
rsaCsp.FromXmlString(string.Format(
"<RSAKeyValue><Modulus>{1}</Modulus><Exponent>{0}</Exponent></RSAKeyValue>",
Convert.ToBase64String(PubExp), Convert.ToBase64String(PubMod)));