-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathmembers.cs
More file actions
76 lines (68 loc) · 2.95 KB
/
members.cs
File metadata and controls
76 lines (68 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// This sample demonstrates how to use each member of the CryptoConfig class.
//<Snippet1>
using System;
using System.Security.Cryptography;
class Members
{
static void Main(string[] args)
{
// Create a CryptoConfig object to store configuration information.
//<Snippet2>
CryptoConfig cryptoConfig = new CryptoConfig();
//</Snippet2>
// Retrieve the class path for CryptoConfig.
//<Snippet7>
string classDescription = cryptoConfig.ToString();
//</Snippet7>
// Create a new SHA1 provider.
//<Snippet4>
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends using a NIST-approved hash function.
SHA1CryptoServiceProvider SHA1alg =
(SHA1CryptoServiceProvider)CryptoConfig.CreateFromName("SHA1");
//</Snippet4>
// Create an RSAParameters with the TestContainer key container.
//<Snippet5>
CspParameters parameters = new CspParameters();
parameters.KeyContainerName = "TestContainer";
Object[] argsArray = new Object[] {parameters};
// Instantiate the RSA provider instance accessing the TestContainer
// key container.
RSA rsa = (RSA)
CryptoConfig.CreateFromName("RSA",argsArray);
//</Snippet5>
// Use the MapNameToOID method to get an object identifier
// (OID) from the string name of the SHA1 algorithm.
//<Snippet3>
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends using a NIST-approved hash function.
string sha1Oid = CryptoConfig.MapNameToOID("SHA1");
//</Snippet3>
// Encode the specified object identifier.
//<Snippet6>
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends using a NIST-approved hash function.
byte[] encodedMessage = CryptoConfig.EncodeOID(sha1Oid);
//</Snippet6>
// 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();
}
}
//
// This sample produces the following output:
//
// ** 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.
//</Snippet1>