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

◆ SignHash()

unsafe override byte[] System.Security.Cryptography.RSACng.SignHash ( byte[] hash,
HashAlgorithmName hashAlgorithm,
RSASignaturePadding padding )
inlinevirtual

Reimplemented from System.Security.Cryptography.RSA.

Definition at line 575 of file RSACng.cs.

576 {
577 if (hash == null)
578 {
579 throw new ArgumentNullException("hash");
580 }
581 string name = hashAlgorithm.Name;
582 if (string.IsNullOrEmpty(name))
583 {
585 }
586 if (padding == null)
587 {
588 throw new ArgumentNullException("padding");
589 }
590 if (hash.Length != GetHashSizeInBytes(hashAlgorithm))
591 {
592 throw new CryptographicException(System.SR.Cryptography_SignHash_WrongSize);
593 }
596 try
597 {
598 int estimatedSize = KeySize / 8;
599 switch (padding.Mode)
600 {
601 case RSASignaturePaddingMode.Pkcs1:
602 {
603 global::Interop.BCrypt.BCRYPT_PKCS1_PADDING_INFO bCRYPT_PKCS1_PADDING_INFO = default(global::Interop.BCrypt.BCRYPT_PKCS1_PADDING_INFO);
604 bCRYPT_PKCS1_PADDING_INFO.pszAlgId = intPtr;
605 global::Interop.BCrypt.BCRYPT_PKCS1_PADDING_INFO bCRYPT_PKCS1_PADDING_INFO2 = bCRYPT_PKCS1_PADDING_INFO;
606 return keyHandle.SignHash(hash, global::Interop.NCrypt.AsymmetricPaddingMode.NCRYPT_PAD_PKCS1_FLAG, &bCRYPT_PKCS1_PADDING_INFO2, estimatedSize);
607 }
609 {
610 global::Interop.BCrypt.BCRYPT_PSS_PADDING_INFO bCRYPT_PSS_PADDING_INFO = default(global::Interop.BCrypt.BCRYPT_PSS_PADDING_INFO);
611 bCRYPT_PSS_PADDING_INFO.pszAlgId = intPtr;
612 bCRYPT_PSS_PADDING_INFO.cbSalt = hash.Length;
613 global::Interop.BCrypt.BCRYPT_PSS_PADDING_INFO bCRYPT_PSS_PADDING_INFO2 = bCRYPT_PSS_PADDING_INFO;
614 return keyHandle.SignHash(hash, global::Interop.NCrypt.AsymmetricPaddingMode.NCRYPT_PAD_PSS_FLAG, &bCRYPT_PSS_PADDING_INFO2, estimatedSize);
615 }
616 default:
617 throw new CryptographicException(System.SR.Cryptography_UnsupportedPaddingMode);
618 }
619 }
620 finally
621 {
623 }
624 }
static void FreeHGlobal(IntPtr hglobal)
Definition Marshal.cs:1680
static unsafe IntPtr StringToHGlobalUni(string? s)
Definition Marshal.cs:1310
static string Cryptography_UnsupportedPaddingMode
Definition SR.cs:160
static string Cryptography_SignHash_WrongSize
Definition SR.cs:142
static string Cryptography_HashAlgorithmNameNullOrEmpty
Definition SR.cs:60
Definition SR.cs:7
static int GetHashSizeInBytes(HashAlgorithmName hashAlgorithm)
Definition RSACng.cs:566
SafeNCryptKeyHandle GetDuplicatedKeyHandle()
Definition RSACng.cs:105

References System.SR.Cryptography_HashAlgorithmNameNullOrEmpty, System.SR.Cryptography_SignHash_WrongSize, System.SR.Cryptography_UnsupportedPaddingMode, System.Runtime.InteropServices.Marshal.FreeHGlobal(), System.Security.Cryptography.RSACng.GetDuplicatedKeyHandle(), System.Security.Cryptography.RSACng.GetHashSizeInBytes(), System.Security.Cryptography.AsymmetricAlgorithm.KeySize, System.Security.Cryptography.RSASignaturePadding.Mode, System.Security.Cryptography.HashAlgorithmName.Name, and System.Runtime.InteropServices.Marshal.StringToHGlobalUni().