本文整理汇总了C#中System.Security.Cryptography.RSACryptoServiceProvider.PersistKeyInCsp属性的典型用法代码示例。如果您正苦于以下问题:C# RSACryptoServiceProvider.PersistKeyInCsp属性的具体用法?C# RSACryptoServiceProvider.PersistKeyInCsp怎么用?C# RSACryptoServiceProvider.PersistKeyInCsp使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Security.Cryptography.RSACryptoServiceProvider
的用法示例。
在下文中一共展示了RSACryptoServiceProvider.PersistKeyInCsp属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Security.Cryptography;
class RSACSPSample
{
static void Main()
{
string KeyContainerName = "MyKeyContainer";
//Create a new key and persist it in
//the key container.
RSAPersistKeyInCSP(KeyContainerName);
//Delete the key from the key container.
RSADeleteKeyInCSP(KeyContainerName);
}
public static void RSAPersistKeyInCSP(string ContainerName)
{
try
{
// Create a new instance of CspParameters. Pass
// 13 to specify a DSA container or 1 to specify
// an RSA container. The default is 1.
CspParameters cspParams = new CspParameters();
// Specify the container name using the passed variable.
cspParams.KeyContainerName = ContainerName;
//Create a new instance of RSACryptoServiceProvider to generate
//a new key pair. Pass the CspParameters class to persist the
//key in the container. The PersistKeyInCsp property is true by
//default, allowing the key to be persisted.
RSACryptoServiceProvider RSAalg = new RSACryptoServiceProvider(cspParams);
//Indicate that the key was persisted.
Console.WriteLine("The RSA key was persisted in the container, \"{0}\".", ContainerName);
}
catch(CryptographicException e)
{
Console.WriteLine(e.Message);
}
}
public static void RSADeleteKeyInCSP(string ContainerName)
{
try
{
// Create a new instance of CspParameters. Pass
// 13 to specify a DSA container or 1 to specify
// an RSA container. The default is 1.
CspParameters cspParams = new CspParameters();
// Specify the container name using the passed variable.
cspParams.KeyContainerName = ContainerName;
//Create a new instance of RSACryptoServiceProvider.
//Pass the CspParameters class to use the
//key in the container.
RSACryptoServiceProvider RSAalg = new RSACryptoServiceProvider(cspParams);
//Explicitly set the PersistKeyInCsp property to false
//to delete the key entry in the container.
RSAalg.PersistKeyInCsp = false;
//Call Clear to release resources and delete the key from the container.
RSAalg.Clear();
//Indicate that the key was persisted.
Console.WriteLine("The RSA key was deleted from the container, \"{0}\".", ContainerName);
}
catch(CryptographicException e)
{
Console.WriteLine(e.Message);
}
}
}
开发者ID:.NET开发者,项目名称:System.Security.Cryptography,代码行数:80,代码来源:RSACryptoServiceProvider.PersistKeyInCsp