请教关于使用密钥容器转换密钥的问题(请高手和专家看看,不知道专家名字)

kill3434 2007-12-11 04:11:12
使用 SN.exe -k制出snk文件
使用 sn -m n 切换到用户模式
使用sn -i *.snk MyContainer将密钥对导入名为“MyContainer”的密钥容器中

使用程序:
CspParameters cp = new CspParameters();
cp.KeyContainerName = "MyContainer";

RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cp);

textBox1.text=rsa.ToXmlString(false);

发现得出的xml格式公匙并不是snk中对应的

验证过程如下:
记住xml格式公匙
使用sn -d MyContainer删除容器
再重新导入并重新运行程序,发现得出的xml格式公匙和上一次不一样

发现容器名称是对应的,好像密钥不一样。如果没有使用SN创建密钥容器,运行这段程序可以自动创建同名的密钥容器,用SN可以删除程序创建的同名容器

我的需要是,我想从snk形式文件导出xml形式的密钥密钥对已供程序使用,不知道怎样实现?
...全文
220 35 打赏 收藏 转发到动态 举报
写回复
用AI写文章
35 条回复
切换为时间正序
请发表友善的回复…
发表回复
kill3434 2008-01-07
  • 打赏
  • 举报
回复
楼上只是MSDN上的吧?不管用呀
frankla 2008-01-05
  • 打赏
  • 举报
回复
RSACryptoServiceProvider 可以自己创建KEYPAIR 啊
using System;
using System.IO;
using System.Security.Cryptography;

public class StoreKey

{
public static void Main()
{
try
{
// Create a key and save it in a container.
GenKey_SaveInContainer("MyKeyContainer");

// Retrieve the key from the container.
GetKeyFromContainer("MyKeyContainer");

// Delete the key from the container.
DeleteKeyFromContainer("MyKeyContainer");

// Create a key and save it in a container.
GenKey_SaveInContainer("MyKeyContainer");

// Delete the key from the container.
DeleteKeyFromContainer("MyKeyContainer");
}
catch(CryptographicException e)
{
Console.WriteLine(e.Message);
}

}

public static void GenKey_SaveInContainer(string ContainerName)
{
// Create the CspParameters object and set the key container
// name used to store the RSA key pair.
CspParameters cp = new CspParameters();
cp.KeyContainerName = ContainerName;

// Create a new instance of RSACryptoServiceProvider that accesses
// the key container MyKeyContainerName.
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cp);

// Display the key information to the console.
Console.WriteLine("Key added to container: \n {0}", rsa.ToXmlString(true));
}

public static void GetKeyFromContainer(string ContainerName)
{
// Create the CspParameters object and set the key container
// name used to store the RSA key pair.
CspParameters cp = new CspParameters();
cp.KeyContainerName = ContainerName;

// Create a new instance of RSACryptoServiceProvider that accesses
// the key container MyKeyContainerName.
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cp);

// Display the key information to the console.
Console.WriteLine("Key retrieved from container : \n {0}", rsa.ToXmlString(true));
}

public static void DeleteKeyFromContainer(string ContainerName)
{
// Create the CspParameters object and set the key container
// name used to store the RSA key pair.
CspParameters cp = new CspParameters();
cp.KeyContainerName = ContainerName;

// Create a new instance of RSACryptoServiceProvider that accesses
// the key container.
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cp);

// Delete the key entry in the container.
rsa.PersistKeyInCsp = false;

// Call Clear to release resources and delete the key from the container.
rsa.Clear();

Console.WriteLine("Key deleted.");
}
}
kill3434 2008-01-05
  • 打赏
  • 举报
回复
那就只有再顶了
wenbin 2008-01-04
  • 打赏
  • 举报
回复
哎,我弄的还不到你那水平呢
看.NET本质论说得我晕
搞了半天也就弄出个密匙
怎么用它不会!
kill3434 2008-01-04
  • 打赏
  • 举报
回复
没人回答了?还是问题不值?
kill3434 2008-01-04
  • 打赏
  • 举报
回复
没人回答了?还是问题不值?
kill3434 2008-01-01
  • 打赏
  • 举报
回复
再顶
kill3434 2007-12-29
  • 打赏
  • 举报
回复
不能再顶了,谁帮一下继续顶,给分
kill3434 2007-12-29
  • 打赏
  • 举报
回复
看顶到什么时候
kill3434 2007-12-26
  • 打赏
  • 举报
回复
没条件上网
到别处到网吧花钱也看不到答案
chengqscjh 2007-12-26
  • 打赏
  • 举报
回复
帮顶下
yeefa 2007-12-26
  • 打赏
  • 举报
回复
怎么是密钥对称我也不清楚
还有怎么样去配对
帮顶,学习......
pciak 2007-12-26
  • 打赏
  • 举报
回复
帮顶
kill3434 2007-12-26
  • 打赏
  • 举报
回复
没条件上网
到别处到网吧花钱也看不到答案
kill3434 2007-12-26
  • 打赏
  • 举报
回复
看顶到什么时候
lwl0376 2007-12-25
  • 打赏
  • 举报
回复
关注
kill3434 2007-12-25
  • 打赏
  • 举报
回复
这么长时间没答案,没人遇到过这个问题吗?顺手帮一下呀
kill3434 2007-12-25
  • 打赏
  • 举报
回复
再顶
ben3_net 2007-12-25
  • 打赏
  • 举报
回复
学习,这个东西基本上没有用过
kill3434 2007-12-25
  • 打赏
  • 举报
回复
再顶
加载更多回复(15)

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧