使用 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形式的密钥密钥对已供程序使用,不知道怎样实现?
使用 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形式的密钥密钥对已供程序使用,不知道怎样实现?
解决方案 »
- 关于LINQ的一个问题!疑点看红色字体这行!
- 急急急!!!水晶报表
- 求字段格式是money乘以0.95,正确的写法
- |zyciis| C# Hook 勾子第三贴:我照网上的一个例子做,但不知道如何来判断当按下二个键的时候不处理如 Win + D
- 图片上传问题 急
- C1TrueDBGrid合计行问题 在线等待
- winfrom 中 关于 ListView 的问题
- 如何将很长的字符串整齐地显示在winform某控件中?
- vs2005 DataGridview 读取XML 文件问题 :提示无法创建字段 students 的子列表。
- C#必败(之三)!!!!!!!!!
- 哪里有Developer Express的套件for .net 2005下载
- 本地注册机是怎么实现的?
看.NET本质论说得我晕
搞了半天也就弄出个密匙
怎么用它不会!
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.");
}
}