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

◆ ImportParameters()

unsafe override void System.Security.Cryptography.RSACng.ImportParameters ( RSAParameters parameters)
inline

Definition at line 375 of file RSACng.cs.

376 {
377 if (parameters.Exponent == null || parameters.Modulus == null)
378 {
379 throw new CryptographicException(System.SR.Cryptography_InvalidRsaParameters);
380 }
381 bool flag;
382 if (parameters.D == null)
383 {
384 flag = false;
385 if (parameters.P != null || parameters.DP != null || parameters.Q != null || parameters.DQ != null || parameters.InverseQ != null)
386 {
387 throw new CryptographicException(System.SR.Cryptography_InvalidRsaParameters);
388 }
389 }
390 else
391 {
392 flag = true;
393 if (parameters.P == null || parameters.DP == null || parameters.Q == null || parameters.DQ == null || parameters.InverseQ == null)
394 {
395 throw new CryptographicException(System.SR.Cryptography_InvalidRsaParameters);
396 }
397 int num = (parameters.Modulus.Length + 1) / 2;
398 if (parameters.D.Length != parameters.Modulus.Length || parameters.P.Length != num || parameters.Q.Length != num || parameters.DP.Length != num || parameters.DQ.Length != num || parameters.InverseQ.Length != num)
399 {
400 throw new CryptographicException(System.SR.Cryptography_InvalidRsaParameters);
401 }
402 }
403 int num2 = sizeof(global::Interop.BCrypt.BCRYPT_RSAKEY_BLOB) + parameters.Exponent.Length + parameters.Modulus.Length;
404 if (flag)
405 {
406 num2 += parameters.P.Length + parameters.Q.Length;
407 }
408 byte[] array = new byte[num2];
409 fixed (byte* ptr = &array[0])
410 {
411 global::Interop.BCrypt.BCRYPT_RSAKEY_BLOB* ptr2 = (global::Interop.BCrypt.BCRYPT_RSAKEY_BLOB*)ptr;
412 ptr2->Magic = (flag ? global::Interop.BCrypt.KeyBlobMagicNumber.BCRYPT_RSAPRIVATE_MAGIC : global::Interop.BCrypt.KeyBlobMagicNumber.BCRYPT_RSAPUBLIC_MAGIC);
413 ptr2->BitLength = parameters.Modulus.Length * 8;
414 ptr2->cbPublicExp = parameters.Exponent.Length;
415 ptr2->cbModulus = parameters.Modulus.Length;
416 if (flag)
417 {
418 ptr2->cbPrime1 = parameters.P.Length;
419 ptr2->cbPrime2 = parameters.Q.Length;
420 }
421 int offset = sizeof(global::Interop.BCrypt.BCRYPT_RSAKEY_BLOB);
422 global::Interop.BCrypt.Emit(array, ref offset, parameters.Exponent);
423 global::Interop.BCrypt.Emit(array, ref offset, parameters.Modulus);
424 if (flag)
425 {
426 global::Interop.BCrypt.Emit(array, ref offset, parameters.P);
427 global::Interop.BCrypt.Emit(array, ref offset, parameters.Q);
428 }
429 }
430 ImportKeyBlob(array, flag);
431 }
static string Cryptography_InvalidRsaParameters
Definition SR.cs:108
Definition SR.cs:7
void ImportKeyBlob(byte[] rsaBlob, bool includePrivate)
Definition RSACng.cs:72

References System.array, System.SR.Cryptography_InvalidRsaParameters, System.Security.Cryptography.RSAParameters.D, System.Security.Cryptography.RSAParameters.DP, System.Security.Cryptography.RSAParameters.DQ, System.Security.Cryptography.RSAParameters.Exponent, System.Security.Cryptography.RSACng.ImportKeyBlob(), System.Security.Cryptography.RSAParameters.InverseQ, System.Security.Cryptography.RSAParameters.Modulus, System.offset, System.Security.Cryptography.RSAParameters.P, and System.Security.Cryptography.RSAParameters.Q.