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

◆ SignHash()

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

Reimplemented from System.Security.Cryptography.RSA.

Definition at line 574 of file RSAImplementation.cs.

575 {
576 if (hash == null)
577 {
578 throw new ArgumentNullException("hash");
579 }
580 string name = hashAlgorithm.Name;
581 if (string.IsNullOrEmpty(name))
582 {
584 }
585 if (padding == null)
586 {
587 throw new ArgumentNullException("padding");
588 }
589 if (hash.Length != GetHashSizeInBytes(hashAlgorithm))
590 {
591 throw new CryptographicException(System.SR.Cryptography_SignHash_WrongSize);
592 }
595 try
596 {
597 int estimatedSize = KeySize / 8;
598 switch (padding.Mode)
599 {
600 case RSASignaturePaddingMode.Pkcs1:
601 {
602 global::Interop.BCrypt.BCRYPT_PKCS1_PADDING_INFO bCRYPT_PKCS1_PADDING_INFO = default(global::Interop.BCrypt.BCRYPT_PKCS1_PADDING_INFO);
603 bCRYPT_PKCS1_PADDING_INFO.pszAlgId = intPtr;
604 global::Interop.BCrypt.BCRYPT_PKCS1_PADDING_INFO bCRYPT_PKCS1_PADDING_INFO2 = bCRYPT_PKCS1_PADDING_INFO;
605 return keyHandle.SignHash(hash, global::Interop.NCrypt.AsymmetricPaddingMode.NCRYPT_PAD_PKCS1_FLAG, &bCRYPT_PKCS1_PADDING_INFO2, estimatedSize);
606 }
608 {
609 global::Interop.BCrypt.BCRYPT_PSS_PADDING_INFO bCRYPT_PSS_PADDING_INFO = default(global::Interop.BCrypt.BCRYPT_PSS_PADDING_INFO);
610 bCRYPT_PSS_PADDING_INFO.pszAlgId = intPtr;
611 bCRYPT_PSS_PADDING_INFO.cbSalt = hash.Length;
612 global::Interop.BCrypt.BCRYPT_PSS_PADDING_INFO bCRYPT_PSS_PADDING_INFO2 = bCRYPT_PSS_PADDING_INFO;
613 return keyHandle.SignHash(hash, global::Interop.NCrypt.AsymmetricPaddingMode.NCRYPT_PAD_PSS_FLAG, &bCRYPT_PSS_PADDING_INFO2, estimatedSize);
614 }
615 default:
616 throw new CryptographicException(System.SR.Cryptography_UnsupportedPaddingMode);
617 }
618 }
619 finally
620 {
622 }
623 }
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)

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