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

◆ GetOrGenerateKey() [1/2]

CngKey Internal.Cryptography.CngAlgorithmCore.GetOrGenerateKey ( ECCurve? curve)
inline

Definition at line 68 of file CngAlgorithmCore.cs.

69 {
71 if (_lazyKey != null)
72 {
73 return _lazyKey;
74 }
75 CngKeyCreationParameters cngKeyCreationParameters = new CngKeyCreationParameters
76 {
77 ExportPolicy = CngExportPolicies.AllowPlaintextExport
78 };
79 if (curve.Value.IsNamed)
80 {
81 cngKeyCreationParameters.Parameters.Add(CngKey.GetPropertyFromNamedCurve(curve.Value));
82 }
83 else
84 {
85 if (!curve.Value.IsPrime)
86 {
87 throw new PlatformNotSupportedException(System.SR.Format(System.SR.Cryptography_CurveNotSupported, curve.Value.CurveType.ToString()));
88 }
89 ECCurve curve2 = curve.Value;
90 byte[] primeCurveParameterBlob = System.Security.Cryptography.ECCng.GetPrimeCurveParameterBlob(ref curve2);
91 CngProperty item = new CngProperty("ECCParameters", primeCurveParameterBlob, CngPropertyOptions.None);
92 cngKeyCreationParameters.Parameters.Add(item);
93 }
94 try
95 {
96 _lazyKey = CngKey.Create(DefaultKeyType ?? CngAlgorithm.ECDsa, null, cngKeyCreationParameters);
97 }
98 catch (CryptographicException ex)
99 {
100 global::Interop.NCrypt.ErrorCode hResult = (global::Interop.NCrypt.ErrorCode)ex.HResult;
101 if ((curve.Value.IsNamed && hResult == global::Interop.NCrypt.ErrorCode.NTE_INVALID_PARAMETER) || hResult == global::Interop.NCrypt.ErrorCode.NTE_NOT_SUPPORTED)
102 {
103 throw new PlatformNotSupportedException(System.SR.Format(System.SR.Cryptography_CurveNotSupported, curve.Value.Oid.FriendlyName), ex);
104 }
105 throw;
106 }
107 return _lazyKey;
108 }
static string Cryptography_CurveNotSupported
Definition SR.cs:64
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
Definition SR.cs:7
static CngKey Create(CngAlgorithm algorithm)
Definition CngKey.cs:278
static CngProperty GetPropertyFromNamedCurve(ECCurve curve)
Definition CngKey.cs:481
static unsafe byte[] GetPrimeCurveParameterBlob(ref ECCurve curve)
Definition ECCng.cs:194

References Internal.Cryptography.CngAlgorithmCore._lazyKey, System.Collections.ObjectModel.Collection< T >.Add(), System.Security.Cryptography.CngKey.Create(), System.SR.Cryptography_CurveNotSupported, System.Security.Cryptography.ECCurve.CurveType, Internal.Cryptography.CngAlgorithmCore.DefaultKeyType, System.Security.Cryptography.CngAlgorithm.ECDsa, System.SR.Format(), System.Security.Cryptography.Oid.FriendlyName, System.Security.Cryptography.ECCng.GetPrimeCurveParameterBlob(), System.Security.Cryptography.CngKey.GetPropertyFromNamedCurve(), System.Exception.HResult, System.Security.Cryptography.ECCurve.IsNamed, System.Security.Cryptography.ECCurve.IsPrime, System.item, System.Security.Cryptography.ECCurve.Oid, System.Security.Cryptography.CngKeyCreationParameters.Parameters, and Internal.Cryptography.CngAlgorithmCore.ThrowIfDisposed().