Skip to content

Commit 0bbd48d

Browse files
authored
Add workaround for Windows 10 (1903) bug to RSABCrypt
1 parent cc31e6e commit 0bbd48d

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/libraries/Common/src/Interop/Windows/BCrypt/Interop.BCryptEncryptDecrypt.RSA.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Runtime.InteropServices;
6+
using System.Security.Cryptography;
67

78
using Microsoft.Win32.SafeHandles;
89

@@ -117,6 +118,14 @@ private static unsafe bool BCryptDecryptRsa(
117118
dwFlags);
118119
}
119120

121+
// Windows 10.1903 can return success when it meant NTE_BUFFER_TOO_SMALL.
122+
if (status == NTSTATUS.STATUS_SUCCESS && written > destination.Length)
123+
{
124+
CryptographicOperations.ZeroMemory(destination);
125+
bytesWritten = 0;
126+
return false;
127+
}
128+
120129
if (status == NTSTATUS.STATUS_SUCCESS)
121130
{
122131
bytesWritten = written;

0 commit comments

Comments
 (0)