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

◆ ImportParameters()

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

Definition at line 374 of file RSAImplementation.cs.

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

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.RSAImplementation.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.