当前位置: 首页>>代码示例>>C#>>正文


C# CryptoConfig类代码示例

本文整理汇总了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();
    }
}
//
开发者ID:.NET开发者,项目名称:System.Security.Cryptography,代码行数:49,代码来源:CryptoConfig

输出:

** 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.


注:本文中的System.Security.Cryptography.CryptoConfig类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。