如何在C#中编写makecert“-sky exchange”和“-sky signature”

时间:2011-04-14 19:33:25

标签: c# encryption rsa encryption-asymmetric makecert

我需要以编程方式在.NET应用程序中创建等效键...

makecert -r -pe -a sha1 -n "CN=MyName" -ss my -sr CurrentUser -sky exchange

makecert -r -pe -a sha1 -n "CN=MyName" -ss my -sr CurrentUser -sky signature

输出最终会像这样使用:

RSACryptoServiceProvider privateKey = new RSACryptoServiceProvider();         
privateKey.FromXmlString("<RSAKeyValue>
<Modulus>wL8s+C8SnnlaaqR+VsyijmxOJOARNa4o7ZNsqfy3+9J9Ol2JNSjjMfQWoUnFtClzJBlZhU5KtuazQe8ZKXTX9YvKoJdRhlsonZkC04qiTMdO/FZIH00GrCRxeQ7XDnQnvPB9Bdsvs//7zrY3f7eLIkpIyK9cQHU+5jjJd5IT0eE=</Modulus>
<Exponent>AQAB</Exponent>
<P>83xxN7jvpg5z16pxz2tIQIdqd/EfmikR9Q2TjG2tosWkUSvtyx0xHZ9EqdTUbSGZZ+jgrabzkafYc7Mplylwew==</P>
<Q>yqcnYSZEXHwJvRWi2V09PNEENTozQZywcFptUUGar9TciaQvoNv3lpnfzUKNBRdhzq4lImxkamajZlTWE5buUw==</Q>
<DP>37HqilkbwyHwB6mOGhPkM3S1ujAK6qTk3JB2iEOTjMGrru9+7maJYz+Z47Wm3ARMXgyzrpZ9m8nqsJFfmoL11Q==</DP>
<DQ>v285tv8kMs2FkZYfuP/oOkwkkneBNejjj68Md2bmzlThZDCyQV2pvB1tmgPVHUsiPNCrCaKlFRISJzfa5rR8Ow==</DQ>
<InverseQ>fgJE2TRe/SS+YqW0/I+FtHrdfbbao0/R3pHD4r4oceZQUemlBgZ7DxOAetebHKthlOdjGkmfWYB8EU4XoWggqw==</InverseQ>
<D>FMLCwjy3wbAKiCANp6XFAJgz1o7365NFv0k41BpvasViTa4TgFFWH2ROJ7M9g0lPqJy+YrhrHcY9mqV5TVjTheQp0JeckrgO2B39XngPMAMMdne3rWGpf0Pfbj3FLfchMk6XYDXSZzCS2CmSeRA4aBMb+4R3YurixyJLrnGRMH0=</D>
</RSAKeyValue>");         

1 个答案:

答案 0 :(得分:0)

我意识到你现在可能已经找到了一个解决方案,但这里的代码是这样的:(基于http://blogs.technet.com/b/jhoward/archive/2005/02/02/365323.aspx

Process.Start("makecert.exe", "-pe -n \"CN=MyCert Root Authority\" -ss my -sr LocalMachine -a sha1 -sky signature -r \"MyCert Root Authority.cer\"");

Process.Start("makecert.exe", "-pe -n \"CN=MyCert\" -ss my -sr LocalMachine -a sha1 -sky exchange -eku 1.3.6.1.5.5.7.3.1 -in \"MyCert Root Authority\" -is MY -ir LocalMachine -sp \"Microsoft RSA SChannel Cryptographic Provider\" -sy 12 \"MyCert.cer\"");