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

◆ FromECPrivateKey() [1/4]

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

Definition at line 38 of file EccKeyFormatHelper.cs.

39 {
40 ValidateParameters(key.Parameters, in algId);
41 if (key.Version != 1)
42 {
43 throw new CryptographicException(System.SR.Cryptography_Der_Invalid_Encoding);
44 }
45 byte[] x = null;
46 byte[] y = null;
47 if (key.PublicKey.HasValue)
48 {
49 ReadOnlySpan<byte> span = key.PublicKey.Value.Span;
50 if (span.Length == 0)
51 {
52 throw new CryptographicException(System.SR.Cryptography_Der_Invalid_Encoding);
53 }
54 if (span[0] != 4)
55 {
56 throw new CryptographicException(System.SR.Cryptography_NotValidPublicOrPrivateKey);
57 }
58 if (span.Length != 2 * key.PrivateKey.Length + 1)
59 {
60 throw new CryptographicException(System.SR.Cryptography_Der_Invalid_Encoding);
61 }
62 x = span.Slice(1, key.PrivateKey.Length).ToArray();
63 y = span.Slice(1 + key.PrivateKey.Length).ToArray();
64 }
65 ECDomainParameters domainParameters = ((!key.Parameters.HasValue) ? ECDomainParameters.Decode(algId.Parameters.Value, AsnEncodingRules.DER) : key.Parameters.Value);
66 ret = new ECParameters
67 {
68 Curve = GetCurve(domainParameters),
69 Q =
70 {
71 X = x,
72 Y = y
73 },
74 D = key.PrivateKey.ToArray()
75 };
76 ret.Validate();
77 }
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.