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

◆ TrySignHash()

unsafe override bool System.Security.Cryptography.RSAImplementation.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 625 of file RSAImplementation.cs.

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