什么是签名的程序集在C#中的公钥的结构? [英] What is the structure of the public key of a signed assembly in C#?
问题描述
使用此代码来获取公共密钥字节...
Using this code to retrieve the public key bytes...
var pubKey =
AppDomain.CurrentDomain.DomainManager.EntryAssembly
.GetName().GetPublicKey();
什么是在开始这个共同结构的关键(前32个字节)?
这不是ASN.1和它可能不是可变的。我可以谷歌,并得到重复。
What is this common structure at the start (first 32 bytes) of the key? It's not ASN.1 and it might not be variable. I can google it and get repeats.
// 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
( 00 04
BE)是1024(位), 0x80的
为128(字节,八分之一千○二十四)。
Is it all reversed or just part of it (e.g. the modulus at the end)? 52 53 41 31
is a string of RSA1
.
My key's modulus is 1024 bit, so I was looking for something that described the length.
0x0400
(00 04
B.E.) would be 1024 (bits), 0x80
would be 128 (bytes, 1024/8).
// 00 04 00 00 01 00 01 00
这是去年4至6公用指数?或大或小尾数?是最后一个空终止或间隔?
Are these last 4 to 6 the public exponent? Big or little endian? Is the last null a terminator or spacer?
调查实施(.NET和Mono) RSAPKCS1SignatureFormatter
和 RSAPKCS1SignatureDeformatter
不随和。
Investigations into implementations (.NET and Mono) of RSAPKCS1SignatureFormatter
and RSAPKCS1SignatureDeformatter
are not easy going.
的删除修改,回答自己的问题......除非有人想出了一个更好的答案或添加细节,包括原由。的
推荐答案
我无法停止咬我的指甲努力工作在RSAPUBKEY向后从CALG_RSA_SIGN = 0x00002400,跌跌撞撞,然后PUBLICKEYSTRUC最后PUBLICKEYBLOB。
哦,现在我可以正式地解析它。 $ B如果有任何结构已经在.NET框架来处理呢?
I couldn't stop biting my nails trying to work backwards from CALG_RSA_SIGN = 0x00002400, and stumbled upon RSAPUBKEY, then PUBLICKEYSTRUC and finally PublicKeyBlob. Well now I can parse it formally. Wonder if there is any struct already in the .NET framework for handling this?
的 https://msdn.microsoft.com/en-us/library/ee442238.aspx
嘿,这些神奇的数字看起来很熟悉。这是什么意思...
Oh hey, these magical numbers look familiar. What do they mean...
它是的 https://msdn.microsoft.com/en-us/library/ms232463.aspx ?
// 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
因此,使用该信息(不能得到rsaCsp.ImportParameters到右工作)...
So using this information (couldn't get rsaCsp.ImportParameters to work right)...
var rsaCsp = new RSACryptoServiceProvider(BitLength);
rsaCsp.FromXmlString(string.Format(
"<RSAKeyValue><Modulus>{1}</Modulus><Exponent>{0}</Exponent></RSAKeyValue>",
Convert.ToBase64String(PubExp), Convert.ToBase64String(PubMod)));
现在你必须从你的程序集的SN PK签名认证的有效rsaCsp。
Now you have a valid rsaCsp for signature authentication from your assembly's SN PK.
这篇关于什么是签名的程序集在C#中的公钥的结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!