本文整理汇总了C#中System.Security.Cryptography.RSACryptoServiceProvider.UseMachineKeyStore属性的典型用法代码示例。如果您正苦于以下问题:C# RSACryptoServiceProvider.UseMachineKeyStore属性的具体用法?C# RSACryptoServiceProvider.UseMachineKeyStore怎么用?C# RSACryptoServiceProvider.UseMachineKeyStore使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Security.Cryptography.RSACryptoServiceProvider
的用法示例。
在下文中一共展示了RSACryptoServiceProvider.UseMachineKeyStore属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Security.Cryptography;
public class RSAKeyStoreSample
{
public static void Main()
{
// Set the static UseMachineKeyStore property to use the machine key
// store instead of the user profile key store. All CSP instances not
// initialized with CspParameters will use this setting.
RSACryptoServiceProvider.UseMachineKeyStore = true;
try
{
// This CSP instance will use the Machine Store as set above and is
// initialized with no parameters.
using (RSACryptoServiceProvider RSAalg = new RSACryptoServiceProvider())
{
ShowContainerInfo(RSAalg.CspKeyContainerInfo);
RSAalg.PersistKeyInCsp = false;
}
CspParameters cspParams = new CspParameters();
cspParams.KeyContainerName = "MyKeyContainer";
// This CSP instance will use the User Store since cspParams are used.
using (RSACryptoServiceProvider RSAalg = new RSACryptoServiceProvider(cspParams))
{
ShowContainerInfo(RSAalg.CspKeyContainerInfo);
RSAalg.PersistKeyInCsp = false;
}
cspParams.Flags |= CspProviderFlags.UseMachineKeyStore;
// This CSP instance will use the Machine Store. Although cspParams are used,
// the cspParams.Flags is set to CspProviderFlags.UseMachineKeyStore.
using (RSACryptoServiceProvider RSAalg = new RSACryptoServiceProvider(cspParams))
{
ShowContainerInfo(RSAalg.CspKeyContainerInfo);
RSAalg.PersistKeyInCsp = false;
}
}
catch (CryptographicException e)
{
Console.WriteLine("Exception: {0}", e.GetType().FullName);
Console.WriteLine(e.Message);
}
}
public static void ShowContainerInfo(CspKeyContainerInfo containerInfo)
{
string keyStore;
Console.WriteLine();
if (containerInfo.MachineKeyStore)
{
keyStore = "Machine Store";
}
else
{
keyStore = "User Store";
}
Console.WriteLine("Key Store: {0}", keyStore);
Console.WriteLine("Key Provider: {0}", containerInfo.ProviderName);
Console.WriteLine("Key Container: \"{0}\"", containerInfo.KeyContainerName);
Console.WriteLine("Generated: {0}", containerInfo.RandomlyGenerated);
Console.WriteLine("Key Nubmer: {0}", containerInfo.KeyNumber);
Console.WriteLine("Removable Key: {0}", containerInfo.Removable);
}
}
开发者ID:.NET开发者,项目名称:System.Security.Cryptography,代码行数:71,代码来源:RSACryptoServiceProvider.UseMachineKeyStore