本文整理汇总了C#中System.Security.Cryptography.CryptoConfig类的典型用法代码示例。如果您正苦于以下问题:C# CryptoConfig类的具体用法?C# CryptoConfig怎么用?C# CryptoConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CryptoConfig类属于System.Security.Cryptography命名空间,在下文中一共展示了CryptoConfig类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Security.Cryptography;
class Members
{
static void Main(string[] args)
{
// Create a CryptoConfig object to store configuration information.
CryptoConfig cryptoConfig = new CryptoConfig();
// Retrieve the class path for CryptoConfig.
string classDescription = cryptoConfig.ToString();
// Create a new SHA1 provider.
SHA1CryptoServiceProvider SHA1alg =
(SHA1CryptoServiceProvider)CryptoConfig.CreateFromName("SHA1");
// Create an RSAParameters with the TestContainer key container.
CspParameters parameters = new CspParameters();
parameters.KeyContainerName = "TestContainer";
Object[] argsArray = new Object[] {parameters};
// Instantiate the RSA provider instance accessing the TestContainer
// key container.
RSACryptoServiceProvider rsaProvider = (RSACryptoServiceProvider)
CryptoConfig.CreateFromName("RSA",argsArray);
// Use the MapNameToOID method to get an object identifier
// (OID) from the string name of the SHA1 algorithm.
string sha1Oid = CryptoConfig.MapNameToOID("SHA1");
// Encode the specified object identifier.
byte[] encodedMessage = CryptoConfig.EncodeOID(sha1Oid);
// Display the results to the console.
Console.WriteLine("** " + classDescription + " **");
Console.WriteLine("Created an RSA provider " +
"with a KeyContainerName called " + parameters.KeyContainerName +
".");
Console.WriteLine("Object identifier from the SHA1 name:" + sha1Oid);
Console.WriteLine("The object identifier encoded: " +
System.Text.Encoding.ASCII.GetString(encodedMessage));
Console.WriteLine("This sample completed successfully; " +
"press Enter to exit.");
Console.ReadLine();
}
}
//
输出:
** System.Security.Cryptography.CryptoConfig ** Created an RSA provider with a KeyContainerName called TestContainer. Object identifier from the SHA1 name:1.3.14.3.2.26 The object identifier encoded: HH*((*H9 This sample completed successfully; press Enter to exit.