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

◆ FromECPrivateKey() [4/4]

static void System.Security.Cryptography.EccKeyFormatHelper.FromECPrivateKey ( System::Security::Cryptography::Asn1::ECPrivateKey key,
in System::Security::Cryptography::Asn1::AlgorithmIdentifierAsn algId,
out ECParameters ret )
inlinestaticpackage

Definition at line 10 of file EccKeyFormatHelper.cs.

11 {
12 ValidateParameters(key.Parameters, in algId);
13 if (key.Version != 1)
14 {
15 throw new CryptographicException(System.SR.Cryptography_Der_Invalid_Encoding);
16 }
17 byte[] x = null;
18 byte[] y = null;
19 if (key.PublicKey.HasValue)
20 {
21 ReadOnlySpan<byte> span = key.PublicKey.Value.Span;
22 if (span.Length == 0)
23 {
24 throw new CryptographicException(System.SR.Cryptography_Der_Invalid_Encoding);
25 }
26 if (span[0] != 4)
27 {
28 throw new CryptographicException(System.SR.Cryptography_NotValidPublicOrPrivateKey);
29 }
30 if (span.Length != 2 * key.PrivateKey.Length + 1)
31 {
32 throw new CryptographicException(System.SR.Cryptography_Der_Invalid_Encoding);
33 }
34 x = span.Slice(1, key.PrivateKey.Length).ToArray();
35 y = span.Slice(1 + key.PrivateKey.Length).ToArray();
36 }
37 System.Security.Cryptography.Asn1.ECDomainParameters domainParameters = ((!key.Parameters.HasValue) ? System.Security.Cryptography.Asn1.ECDomainParameters.Decode(algId.Parameters.Value, AsnEncodingRules.DER) : key.Parameters.Value);
38 ret = new ECParameters
39 {
40 Curve = GetCurve(domainParameters),
41 Q =
42 {
43 X = x,
44 Y = y
45 },
46 D = key.PrivateKey.ToArray()
47 };
48 ret.Validate();
49 }
static string Cryptography_Der_Invalid_Encoding
Definition SR.cs:50
static string Cryptography_NotValidPublicOrPrivateKey
Definition SR.cs:122
Definition SR.cs:7
static void ValidateParameters(ECDomainParameters? keyParameters, in AlgorithmIdentifierAsn algId)
static ECCurve GetCurve(ECDomainParameters domainParameters)
static ECDomainParameters Decode(ReadOnlyMemory< byte > encoded, AsnEncodingRules ruleSet)

References System.SR.Cryptography_Der_Invalid_Encoding, System.SR.Cryptography_NotValidPublicOrPrivateKey, System.D, System.Security.Cryptography.Asn1.ECDomainParameters.Decode(), System.Security.Cryptography.EccKeyFormatHelper.GetCurve(), System.key, System.ReadOnlySpan< T >.Length, System.Q, System.ReadOnlySpan< T >.Slice(), System.Security.Cryptography.EccKeyFormatHelper.ValidateParameters(), System.X, and System.Y.