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

◆ ReadDsaPrivateKey()

static void System.Security.Cryptography.DSAKeyFormatHelper.ReadDsaPrivateKey ( ReadOnlyMemory< byte > xBytes,
in AlgorithmIdentifierAsn algId,
out DSAParameters ret )
inlinestaticpackage

Definition at line 11 of file DSAKeyFormatHelper.cs.

12 {
13 if (!algId.Parameters.HasValue)
14 {
15 throw new CryptographicException(System.SR.Cryptography_Der_Invalid_Encoding);
16 }
17 DssParms dssParms = DssParms.Decode(algId.Parameters.Value, AsnEncodingRules.BER);
18 ret = new DSAParameters
19 {
20 P = dssParms.P.ToByteArray(isUnsigned: true, isBigEndian: true),
21 Q = dssParms.Q.ToByteArray(isUnsigned: true, isBigEndian: true)
22 };
23 ret.G = dssParms.G.ExportKeyParameter(ret.P.Length);
24 BigInteger bigInteger;
25 try
26 {
27 int bytesConsumed;
28 ReadOnlySpan<byte> value = AsnDecoder.ReadIntegerBytes(xBytes.Span, AsnEncodingRules.DER, out bytesConsumed);
29 if (bytesConsumed != xBytes.Length)
30 {
31 throw new CryptographicException(System.SR.Cryptography_Der_Invalid_Encoding);
32 }
33 bigInteger = new BigInteger(value, isUnsigned: true, isBigEndian: true);
34 }
35 catch (AsnContentException inner)
36 {
37 throw new CryptographicException(System.SR.Cryptography_Der_Invalid_Encoding, inner);
38 }
39 ret.X = bigInteger.ExportKeyParameter(ret.Q.Length);
40 BigInteger value2 = BigInteger.ModPow(dssParms.G, bigInteger, dssParms.P);
41 ret.Y = value2.ExportKeyParameter(ret.P.Length);
42 }
static ReadOnlySpan< byte > ReadIntegerBytes(ReadOnlySpan< byte > source, AsnEncodingRules ruleSet, out int bytesConsumed, Asn1Tag? expectedTag=null)
static string Cryptography_Der_Invalid_Encoding
Definition SR.cs:50
Definition SR.cs:7
static BigInteger ModPow(BigInteger value, BigInteger exponent, BigInteger modulus)
unsafe ReadOnlySpan< T > Span
static DssParms Decode(ReadOnlyMemory< byte > encoded, AsnEncodingRules ruleSet)
Definition DssParms.cs:14

References System.SR.Cryptography_Der_Invalid_Encoding, System.Security.Cryptography.Asn1.DssParms.Decode(), System.Security.Cryptography.Asn1.DssParms.G, System.ReadOnlyMemory< T >.Length, System.Numerics.BigInteger.ModPow(), System.P, System.Security.Cryptography.Asn1.DssParms.P, System.Q, System.Security.Cryptography.Asn1.DssParms.Q, System.Formats.Asn1.AsnDecoder.ReadIntegerBytes(), System.ReadOnlyMemory< T >.Span, System.Numerics.BigInteger.ToByteArray(), and System.value.

Referenced by System.Security.Cryptography.DSAKeyFormatHelper.ReadEncryptedPkcs8(), System.Security.Cryptography.DSAKeyFormatHelper.ReadEncryptedPkcs8(), and System.Security.Cryptography.DSAKeyFormatHelper.ReadPkcs8().