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

◆ TrySignHash()

unsafe override bool System.Security.Cryptography.RSACng.TrySignHash ( ReadOnlySpan< byte > hash,
Span< byte > destination,
HashAlgorithmName hashAlgorithm,
RSASignaturePadding padding,
out int bytesWritten )
inlinevirtual

Reimplemented from System.Security.Cryptography.RSA.

Definition at line 626 of file RSACng.cs.

627 {
628 string name = hashAlgorithm.Name;
629 if (string.IsNullOrEmpty(name))
630 {
632 }
633 if (padding == null)
634 {
635 throw new ArgumentNullException("padding");
636 }
638 if (hash.Length != GetHashSizeInBytes(hashAlgorithm))
639 {
640 throw new CryptographicException(System.SR.Cryptography_SignHash_WrongSize);
641 }
643 try
644 {
645 switch (padding.Mode)
646 {
647 case RSASignaturePaddingMode.Pkcs1:
648 {
649 global::Interop.BCrypt.BCRYPT_PKCS1_PADDING_INFO bCRYPT_PKCS1_PADDING_INFO = default(global::Interop.BCrypt.BCRYPT_PKCS1_PADDING_INFO);
650 bCRYPT_PKCS1_PADDING_INFO.pszAlgId = intPtr;
651 global::Interop.BCrypt.BCRYPT_PKCS1_PADDING_INFO bCRYPT_PKCS1_PADDING_INFO2 = bCRYPT_PKCS1_PADDING_INFO;
652 return keyHandle.TrySignHash(hash, destination, global::Interop.NCrypt.AsymmetricPaddingMode.NCRYPT_PAD_PKCS1_FLAG, &bCRYPT_PKCS1_PADDING_INFO2, out bytesWritten);
653 }
655 {
656 global::Interop.BCrypt.BCRYPT_PSS_PADDING_INFO bCRYPT_PSS_PADDING_INFO = default(global::Interop.BCrypt.BCRYPT_PSS_PADDING_INFO);
657 bCRYPT_PSS_PADDING_INFO.pszAlgId = intPtr;
658 bCRYPT_PSS_PADDING_INFO.cbSalt = hash.Length;
659 global::Interop.BCrypt.BCRYPT_PSS_PADDING_INFO bCRYPT_PSS_PADDING_INFO2 = bCRYPT_PSS_PADDING_INFO;
660 return keyHandle.TrySignHash(hash, destination, global::Interop.NCrypt.AsymmetricPaddingMode.NCRYPT_PAD_PSS_FLAG, &bCRYPT_PSS_PADDING_INFO2, out bytesWritten);
661 }
662 default:
663 throw new CryptographicException(System.SR.Cryptography_UnsupportedPaddingMode);
664 }
665 }
666 finally
667 {
669 }
670 }
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.destination, System.Runtime.InteropServices.Marshal.FreeHGlobal(), System.Security.Cryptography.RSACng.GetDuplicatedKeyHandle(), System.Security.Cryptography.RSACng.GetHashSizeInBytes(), System.Security.Cryptography.RSASignaturePadding.Mode, System.Security.Cryptography.HashAlgorithmName.Name, and System.Runtime.InteropServices.Marshal.StringToHGlobalUni().