Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" />
<PackageVersion Include="Meziantou.Analyzer" Version="2.0.205" />
<!-- Should stay on LTS .NET releases. -->
<PackageVersion Include="Microsoft.Bcl.Cryptography" Version="10.0.0-preview.7.25380.108" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="9.0.7" />
<PackageVersion Include="MSTest" Version="3.9.3" />
Expand All @@ -23,4 +24,4 @@
<PackageVersion Include="System.Formats.Asn1" Version="8.0.2" />
<PackageVersion Include="Testcontainers" Version="4.6.0" />
</ItemGroup>
</Project>
</Project>
6 changes: 5 additions & 1 deletion src/Renci.SshNet/Renci.SshNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@
</PackageReference>
</ItemGroup>

<ItemGroup Condition=" !$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0')) ">
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
<PackageReference Include="Microsoft.Bcl.Cryptography" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Formats.Asn1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NET
#if !NETSTANDARD
using System;
using System.Security.Cryptography;

Expand Down
14 changes: 11 additions & 3 deletions src/Renci.SshNet/Security/Cryptography/Ciphers/AesGcmCipher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Loading