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

◆ ExportParameters()

unsafe override DSAParameters System.Security.Cryptography.DSACng.ExportParameters ( bool includePrivateParameters)
inline

Definition at line 315 of file DSACng.cs.

316 {
317 byte[] array = ExportKeyBlob(includePrivateParameters);
318 global::Interop.BCrypt.KeyBlobMagicNumber keyBlobMagicNumber = (global::Interop.BCrypt.KeyBlobMagicNumber)BitConverter.ToInt32(array, 0);
319 CheckMagicValueOfKey(keyBlobMagicNumber, includePrivateParameters);
320 DSAParameters result = default(DSAParameters);
321 fixed (byte* ptr = array)
322 {
323 if (keyBlobMagicNumber == global::Interop.BCrypt.KeyBlobMagicNumber.BCRYPT_DSA_PUBLIC_MAGIC || keyBlobMagicNumber == global::Interop.BCrypt.KeyBlobMagicNumber.BCRYPT_DSA_PRIVATE_MAGIC)
324 {
325 if (array.Length < sizeof(global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB))
326 {
327 throw global::Interop.NCrypt.ErrorCode.E_FAIL.ToCryptographicException();
328 }
329 global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB* ptr2 = (global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB*)ptr;
330 int offset = 8;
331 result.Counter = BinaryPrimitives.ReadInt32BigEndian(global::Interop.BCrypt.Consume(array, ref offset, 4));
332 result.Seed = global::Interop.BCrypt.Consume(array, ref offset, 20);
333 result.Q = global::Interop.BCrypt.Consume(array, ref offset, 20);
334 result.P = global::Interop.BCrypt.Consume(array, ref offset, ptr2->cbKey);
335 result.G = global::Interop.BCrypt.Consume(array, ref offset, ptr2->cbKey);
336 result.Y = global::Interop.BCrypt.Consume(array, ref offset, ptr2->cbKey);
337 if (includePrivateParameters)
338 {
339 result.X = global::Interop.BCrypt.Consume(array, ref offset, 20);
340 }
341 }
342 else
343 {
344 if (array.Length < sizeof(global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB_V2))
345 {
346 throw global::Interop.NCrypt.ErrorCode.E_FAIL.ToCryptographicException();
347 }
348 global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB_V2* ptr3 = (global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB_V2*)ptr;
349 int offset = sizeof(global::Interop.BCrypt.BCRYPT_DSA_KEY_BLOB_V2) - 4;
350 result.Counter = BinaryPrimitives.ReadInt32BigEndian(global::Interop.BCrypt.Consume(array, ref offset, 4));
351 result.Seed = global::Interop.BCrypt.Consume(array, ref offset, ptr3->cbSeedLength);
352 result.Q = global::Interop.BCrypt.Consume(array, ref offset, ptr3->cbGroupSize);
353 result.P = global::Interop.BCrypt.Consume(array, ref offset, ptr3->cbKey);
354 result.G = global::Interop.BCrypt.Consume(array, ref offset, ptr3->cbKey);
355 result.Y = global::Interop.BCrypt.Consume(array, ref offset, ptr3->cbKey);
356 if (includePrivateParameters)
357 {
358 result.X = global::Interop.BCrypt.Consume(array, ref offset, ptr3->cbGroupSize);
359 }
360 }
361 if (result.Counter == -1)
362 {
363 result.Counter = 0;
364 result.Seed = null;
365 }
366 return result;
367 }
368 }
static int ReadInt32BigEndian(ReadOnlySpan< byte > source)
static void CheckMagicValueOfKey(global::Interop.BCrypt.KeyBlobMagicNumber magic, bool includePrivateParameters)
Definition DSACng.cs:370
byte[] ExportKeyBlob(bool includePrivateParameters)
Definition DSACng.cs:67

References System.array, System.Security.Cryptography.DSACng.CheckMagicValueOfKey(), System.Security.Cryptography.DSAParameters.Counter, System.Security.Cryptography.DSACng.ExportKeyBlob(), System.offset, System.Buffers.Binary.BinaryPrimitives.ReadInt32BigEndian(), and System.BitConverter.ToInt32().