本文整理汇总了C#中RSACryptoServiceProvider.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# RSACryptoServiceProvider.Clear方法的具体用法?C# RSACryptoServiceProvider.Clear怎么用?C# RSACryptoServiceProvider.Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RSACryptoServiceProvider
的用法示例。
在下文中一共展示了RSACryptoServiceProvider.Clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Encrypt
public static string Encrypt(string toEncrypt)
{
RSACryptoServiceProvider CSPRSA = null;
string result;
try
{
CSPRSA = new RSACryptoServiceProvider();
CSPRSA.FromXmlString(SAFSecurityKeys.loadKeysFromFile());
byte[] toEncryptArray = Encoding.UTF8.GetBytes(toEncrypt);
result = Convert.ToBase64String(CSPRSA.Decrypt(toEncryptArray, false));
}
catch
{
result = null;
}
finally
{
if (CSPRSA != null)
{
CSPRSA.Clear();
}
}
return result;
}
示例2: RSATest
private static void RSATest()
{
var publicPrivateRsa = new RSACryptoServiceProvider
(
new CspParameters()
{
KeyContainerName = "PublicPrivateKeys",
Flags = CspProviderFlags.UseMachineKeyStore
//Flags = CspProviderFlags.UseDefaultKeyContainer
}
)
{
PersistKeyInCsp = true,
};
var publicRsa = new RSACryptoServiceProvider(
new CspParameters()
{
KeyContainerName = "PublicKey",
Flags = CspProviderFlags.UseMachineKeyStore
//Flags = CspProviderFlags.UseDefaultKeyContainer
}
)
{
PersistKeyInCsp = true
};
//Export the key.
publicRsa.ImportParameters(publicPrivateRsa.ExportParameters(false));
Console.WriteLine(publicRsa.ToXmlString(false));
Console.WriteLine(publicPrivateRsa.ToXmlString(false));
//Dispose those two CSPs.
using (publicRsa)
{
publicRsa.Clear();
}
using (publicPrivateRsa)
{
publicRsa.Clear();
}
//Retrieve keys
publicPrivateRsa = new RSACryptoServiceProvider(
new CspParameters()
{
KeyContainerName = "PublicPrivateKeys",
Flags = CspProviderFlags.UseMachineKeyStore
//Flags = CspProviderFlags.UseDefaultKeyContainer
}
);
publicRsa = new RSACryptoServiceProvider(
new CspParameters()
{
KeyContainerName = "PublicKey",
Flags = CspProviderFlags.UseMachineKeyStore
//Flags = CspProviderFlags.UseDefaultKeyContainer
}
);
Console.WriteLine(publicRsa.ToXmlString(false));
Console.WriteLine(publicPrivateRsa.ToXmlString(false));
using (publicRsa)
{
publicRsa.Clear();
}
using (publicPrivateRsa)
{
publicRsa.Clear();
}
}