Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ECDiffieHellmanCngPublicKey.cs
Go to the documentation of this file.
2
4{
5 private readonly CngKeyBlobFormat _format;
6
7 private readonly string _curveName;
8
9 private bool _disposed;
10
12
13 internal ECDiffieHellmanCngPublicKey(byte[] keyBlob, string curveName, CngKeyBlobFormat format)
14 : base(keyBlob)
15 {
17 _curveName = curveName;
18 }
19
20 protected override void Dispose(bool disposing)
21 {
22 if (disposing)
23 {
24 _disposed = true;
25 }
26 base.Dispose(disposing);
27 }
28
29 public override string ToXmlString()
30 {
32 }
33
35 {
37 }
38
40 {
41 if (publicKeyBlob == null)
42 {
43 throw new ArgumentNullException("publicKeyBlob");
44 }
45 if (format == null)
46 {
47 throw new ArgumentNullException("format");
48 }
49 using CngKey cngKey = CngKey.Import(publicKeyBlob, format);
50 if (cngKey.AlgorithmGroup != CngAlgorithmGroup.ECDiffieHellman)
51 {
53 }
54 return new ECDiffieHellmanCngPublicKey(publicKeyBlob, null, format);
55 }
56
58 {
60 string curveName;
61 byte[] keyBlob = System.Security.Cryptography.ECCng.ExportKeyBlob(key, includePrivateParameters: false, out format, out curveName);
62 return new ECDiffieHellmanCngPublicKey(keyBlob, curveName, format);
63 }
64
65 public CngKey Import()
66 {
67 if (_disposed)
68 {
69 throw new ObjectDisposedException("ECDiffieHellmanCngPublicKey");
70 }
72 }
73
75 {
76 using CngKey key = Import();
77 ECParameters ecParams = default(ECParameters);
78 byte[] ecBlob = System.Security.Cryptography.ECCng.ExportFullKeyBlob(key, includePrivateParameters: false);
79 System.Security.Cryptography.ECCng.ExportPrimeCurveParameters(ref ecParams, ecBlob, includePrivateParameters: false);
80 return ecParams;
81 }
82
84 {
85 using CngKey cngKey = Import();
86 ECParameters ecParams = default(ECParameters);
87 string oidValue;
88 string curveName = cngKey.GetCurveName(out oidValue);
89 if (string.IsNullOrEmpty(curveName))
90 {
91 byte[] ecBlob = System.Security.Cryptography.ECCng.ExportFullKeyBlob(cngKey, includePrivateParameters: false);
92 System.Security.Cryptography.ECCng.ExportPrimeCurveParameters(ref ecParams, ecBlob, includePrivateParameters: false);
93 }
94 else
95 {
96 byte[] ecBlob2 = System.Security.Cryptography.ECCng.ExportKeyBlob(cngKey, includePrivateParameters: false);
97 System.Security.Cryptography.ECCng.ExportNamedCurveParameters(ref ecParams, ecBlob2, includePrivateParameters: false);
98 ecParams.Curve = ECCurve.CreateFromFriendlyName(curveName);
99 }
100 return ecParams;
101 }
102}
static string Cryptography_ArgECDHRequiresECDHKey
Definition SR.cs:42
Definition SR.cs:7
static CngKey Import(ReadOnlySpan< byte > keyBlob, CngKeyBlobFormat format)
Definition CngKey.cs:525
static unsafe void ExportNamedCurveParameters(ref ECParameters ecParams, byte[] ecBlob, bool includePrivateParameters)
Definition ECCng.cs:131
static byte[] ExportKeyBlob(CngKey key, bool includePrivateParameters)
Definition ECCng.cs:25
static unsafe void ExportPrimeCurveParameters(ref ECParameters ecParams, byte[] ecBlob, bool includePrivateParameters)
Definition ECCng.cs:155
static byte[] ExportFullKeyBlob(CngKey key, bool includePrivateParameters)
Definition ECCng.cs:31
static ECDiffieHellmanCngPublicKey FromKey(CngKey key)
static ECDiffieHellmanCngPublicKey FromXmlString(string xml)
static ECDiffieHellmanPublicKey FromByteArray(byte[] publicKeyBlob, CngKeyBlobFormat format)
ECDiffieHellmanCngPublicKey(byte[] keyBlob, string curveName, CngKeyBlobFormat format)
static ECCurve CreateFromFriendlyName(string oidFriendlyName)
Definition ECCurve.cs:135