Skip to content

Commit b9d888b

Browse files
committed
Use native AesGcm for .NET Framework from nuget
1 parent fd05d76 commit b9d888b

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<PackageVersion Include="Meziantou.Analyzer" Version="2.0.201" />
1313

1414
<!-- Should stay on LTS .NET releases. -->
15+
<PackageVersion Include="Microsoft.Bcl.Cryptography" Version="10.0.0-preview.5.25277.114" />
1516
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3" />
1617
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="9.0.5" />
1718
<PackageVersion Include="MSTest" Version="3.9.1" />

src/Renci.SshNet/Renci.SshNet.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@
4949
</PackageReference>
5050
</ItemGroup>
5151

52-
<ItemGroup Condition=" !$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0')) ">
52+
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
53+
<PackageReference Include="Microsoft.Bcl.Cryptography" />
54+
</ItemGroup>
55+
56+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
5357
<PackageReference Include="System.Formats.Asn1" />
5458
</ItemGroup>
5559

src/Renci.SshNet/Security/Cryptography/Ciphers/AesGcmCipher.BclImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if NET
1+
#if !NETSTANDARD
22
using System;
33
using System.Security.Cryptography;
44

src/Renci.SshNet/Security/Cryptography/Ciphers/AesGcmCipher.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal sealed partial class AesGcmCipher : SymmetricCipher, IDisposable
1515
private const int TagSizeInBytes = 16;
1616
private readonly byte[] _iv;
1717
private readonly int _aadLength;
18-
#if NET
18+
#if !NETSTANDARD
1919
private readonly Impl _impl;
2020
#else
2121
private readonly BouncyCastleImpl _impl;
@@ -62,10 +62,18 @@ public AesGcmCipher(byte[] key, byte[] iv, int aadLength)
6262
// SSH AES-GCM requires a 12-octet Initial IV
6363
_iv = iv.Take(12);
6464
_aadLength = aadLength;
65-
#if NET
65+
#if !NETSTANDARD
6666
if (System.Security.Cryptography.AesGcm.IsSupported)
6767
{
68-
_impl = new BclImpl(key, _iv);
68+
try
69+
{
70+
_impl = new BclImpl(key, _iv);
71+
}
72+
catch (DllNotFoundException)
73+
{
74+
// Mono doesn't have BCrypt.dll
75+
_impl = new BouncyCastleImpl(key, _iv);
76+
}
6977
}
7078
else
7179
#endif

0 commit comments

Comments
 (0)