Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ GenerateKey()

void System.Security.Cryptography.ECCngKey.GenerateKey ( ECCurve curve)
inlinepackage

Definition at line 68 of file ECCngKey.cs.

69 {
70 curve.Validate();
72 if (_keyHandle != null)
73 {
74 DisposeKey();
75 }
76 int num = 0;
77 string text;
78 if (curve.IsNamed)
79 {
80 if (string.IsNullOrEmpty(curve.Oid.FriendlyName))
81 {
82 throw new PlatformNotSupportedException(System.SR.Format(System.SR.Cryptography_InvalidCurveOid, curve.Oid.Value));
83 }
84 text = ((!(_algorithmGroup == "ECDSA")) ? ECCng.EcdhCurveNameToAlgorithm(curve.Oid.FriendlyName) : ECCng.EcdsaCurveNameToAlgorithm(curve.Oid.FriendlyName));
85 if (ECCng.IsECNamedCurve(text))
86 {
87 try
88 {
89 _keyHandle = CngKeyLite.GenerateNewExportableKey(text, curve.Oid.FriendlyName);
90 num = CngKeyLite.GetKeyLength(_keyHandle);
91 }
92 catch (CryptographicException ex)
93 {
94 global::Interop.NCrypt.ErrorCode hResult = (global::Interop.NCrypt.ErrorCode)ex.HResult;
95 if ((curve.IsNamed && hResult == global::Interop.NCrypt.ErrorCode.NTE_INVALID_PARAMETER) || hResult == global::Interop.NCrypt.ErrorCode.NTE_NOT_SUPPORTED)
96 {
97 throw new PlatformNotSupportedException(System.SR.Format(System.SR.Cryptography_CurveNotSupported, curve.Oid.FriendlyName), ex);
98 }
99 throw;
100 }
101 }
102 else
103 {
104 switch (text)
105 {
106 case "ECDSA_P256":
107 case "ECDH_P256":
108 num = 256;
109 break;
110 case "ECDSA_P384":
111 case "ECDH_P384":
112 num = 384;
113 break;
114 case "ECDSA_P521":
115 case "ECDH_P521":
116 num = 521;
117 break;
118 default:
120 }
121 _keyHandle = CngKeyLite.GenerateNewExportableKey(text, num);
122 }
123 }
124 else
125 {
126 if (!curve.IsExplicit)
127 {
128 throw new PlatformNotSupportedException(System.SR.Format(System.SR.Cryptography_CurveNotSupported, curve.CurveType.ToString()));
129 }
131 _keyHandle = CngKeyLite.GenerateNewExportableKey(text, ref curve);
132 num = CngKeyLite.GetKeyLength(_keyHandle);
133 }
135 _lastKeySize = num;
136 KeySize = num;
137 }
static string Cryptography_CurveNotSupported
Definition SR.cs:64
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Cryptography_InvalidCurveOid
Definition SR.cs:66
static string Cryptography_InvalidKeySize
Definition SR.cs:92
Definition SR.cs:7
SafeNCryptKeyHandle _keyHandle
Definition ECCngKey.cs:7

References System.Security.Cryptography.ECCngKey._algorithmGroup, System.Security.Cryptography.ECCngKey._keyHandle, System.Security.Cryptography.ECCngKey._lastAlgorithm, System.Security.Cryptography.ECCngKey._lastKeySize, System.SR.Cryptography_CurveNotSupported, System.SR.Cryptography_InvalidCurveOid, System.SR.Cryptography_InvalidKeySize, System.Security.Cryptography.ECCurve.CurveType, System.Security.Cryptography.ECCngKey.DisposeKey(), System.Security.Cryptography.ECCng.EcdhCurveNameToAlgorithm(), System.Security.Cryptography.ECCng.EcdsaCurveNameToAlgorithm(), System.SR.Format(), System.Security.Cryptography.Oid.FriendlyName, System.Security.Cryptography.CngKeyLite.GenerateNewExportableKey(), System.Security.Cryptography.CngKeyLite.GetKeyLength(), System.Exception.HResult, System.Security.Cryptography.ECCng.IsECNamedCurve(), System.Security.Cryptography.ECCurve.IsExplicit, System.Security.Cryptography.ECCurve.IsNamed, System.Security.Cryptography.ECCngKey.KeySize, System.Security.Cryptography.ECCurve.Oid, System.text, System.Security.Cryptography.ECCngKey.ThrowIfDisposed(), System.Security.Cryptography.ECCurve.Validate(), and System.Security.Cryptography.Oid.Value.

Referenced by System.Security.Cryptography.ECDiffieHellmanImplementation.ECDiffieHellmanCng.GenerateKey(), and System.Security.Cryptography.ECDsaImplementation.ECDsaCng.GenerateKey().