blob: f4bb479abcaeb5193f85b0ecb5cac27a4bb3a3d5 (
plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace System.Security.Cryptography {
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class AsymmetricAlgorithm : IDisposable {
protected int KeySizeValue;
protected KeySizes[] LegalKeySizesValue;
//
// public constructors
//
protected AsymmetricAlgorithm() {}
// AsymmetricAlgorithm implements IDisposable
public void Dispose() {
Clear();
}
public void Clear() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
return;
}
//
// public properties
//
public virtual int KeySize {
get { return KeySizeValue; }
set {
int i;
int j;
for (i=0; i<LegalKeySizesValue.Length; i++) {
if (LegalKeySizesValue[i].SkipSize == 0) {
if (LegalKeySizesValue[i].MinSize == value) { // assume MinSize = MaxSize
KeySizeValue = value;
return;
}
} else {
for (j = LegalKeySizesValue[i].MinSize; j<=LegalKeySizesValue[i].MaxSize;
j += LegalKeySizesValue[i].SkipSize) {
if (j == value) {
KeySizeValue = value;
return;
}
}
}
}
throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidKeySize"));
}
}
public virtual KeySizes[] LegalKeySizes {
get { return (KeySizes[]) LegalKeySizesValue.Clone(); }
}
// This method must be implemented by derived classes. In order to conform to the contract, it cannot be abstract.
public virtual String SignatureAlgorithm {
get {
throw new NotImplementedException();
}
}
// This method must be implemented by derived classes. In order to conform to the contract, it cannot be abstract.
public virtual String KeyExchangeAlgorithm {
get {
throw new NotImplementedException();
}
}
//
// public methods
//
static public AsymmetricAlgorithm Create() {
// Use the crypto config system to return an instance of
// the default AsymmetricAlgorithm on this machine
return Create("System.Security.Cryptography.AsymmetricAlgorithm");
}
static public AsymmetricAlgorithm Create(String algName) {
return (AsymmetricAlgorithm) CryptoConfig.CreateFromName(algName);
}
// This method must be implemented by derived classes. In order to conform to the contract, it cannot be abstract.
public virtual void FromXmlString(String xmlString) {
throw new NotImplementedException();
}
// This method must be implemented by derived classes. In order to conform to the contract, it cannot be abstract.
public virtual String ToXmlString(bool includePrivateParameters) {
throw new NotImplementedException();
}
}
}
|