From 2ba463c4d78803350d7105ea0761facad95aecaa Mon Sep 17 00:00:00 2001 From: Scott Xu Date: Sat, 22 Mar 2025 16:47:23 +0800 Subject: [PATCH 1/2] Use native AesGcm for .NET Framework from nuget --- Directory.Packages.props | 3 ++- src/Renci.SshNet/Renci.SshNet.csproj | 6 +++++- .../Cryptography/Ciphers/AesGcmCipher.BclImpl.cs | 2 +- .../Security/Cryptography/Ciphers/AesGcmCipher.cs | 14 +++++++++++--- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 6ae4272d0..f8e49301a 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -11,6 +11,7 @@ + @@ -23,4 +24,4 @@ - \ No newline at end of file + diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj index 446865229..6ec714ac3 100644 --- a/src/Renci.SshNet/Renci.SshNet.csproj +++ b/src/Renci.SshNet/Renci.SshNet.csproj @@ -49,7 +49,11 @@ - + + + + + diff --git a/src/Renci.SshNet/Security/Cryptography/Ciphers/AesGcmCipher.BclImpl.cs b/src/Renci.SshNet/Security/Cryptography/Ciphers/AesGcmCipher.BclImpl.cs index de174d673..69af81e38 100644 --- a/src/Renci.SshNet/Security/Cryptography/Ciphers/AesGcmCipher.BclImpl.cs +++ b/src/Renci.SshNet/Security/Cryptography/Ciphers/AesGcmCipher.BclImpl.cs @@ -1,4 +1,4 @@ -#if NET +#if !NETSTANDARD using System; using System.Security.Cryptography; diff --git a/src/Renci.SshNet/Security/Cryptography/Ciphers/AesGcmCipher.cs b/src/Renci.SshNet/Security/Cryptography/Ciphers/AesGcmCipher.cs index ded36fc0d..81b7b278c 100644 --- a/src/Renci.SshNet/Security/Cryptography/Ciphers/AesGcmCipher.cs +++ b/src/Renci.SshNet/Security/Cryptography/Ciphers/AesGcmCipher.cs @@ -15,7 +15,7 @@ internal sealed partial class AesGcmCipher : SymmetricCipher, IDisposable private const int TagSizeInBytes = 16; private readonly byte[] _iv; private readonly int _aadLength; -#if NET +#if !NETSTANDARD private readonly Impl _impl; #else private readonly BouncyCastleImpl _impl; @@ -62,10 +62,18 @@ public AesGcmCipher(byte[] key, byte[] iv, int aadLength) // SSH AES-GCM requires a 12-octet Initial IV _iv = iv.Take(12); _aadLength = aadLength; -#if NET +#if !NETSTANDARD if (System.Security.Cryptography.AesGcm.IsSupported) { - _impl = new BclImpl(key, _iv); + try + { + _impl = new BclImpl(key, _iv); + } + catch (DllNotFoundException) + { + // Mono doesn't have BCrypt.dll + _impl = new BouncyCastleImpl(key, _iv); + } } else #endif From 177dfbaa146d656df0bab2b28def1aa437f3828a Mon Sep 17 00:00:00 2001 From: Scott Xu Date: Sat, 20 Sep 2025 19:46:32 +0800 Subject: [PATCH 2/2] Update Microsoft.Bcl.Cryptography to RC1 --- Directory.Packages.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index f8e49301a..fae02b24d 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -11,7 +11,7 @@ - + @@ -24,4 +24,4 @@ - + \ No newline at end of file