Skip to content
Closed
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
12 changes: 6 additions & 6 deletions Extensions/CngKeyExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.Security.Cryptography;
using System.Linq;

namespace SecurityDriven.Inferno.Extensions
{
#if NET5_0_OR_GREATER
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public static class CngKeyExtensions
{
static readonly CngKeyCreationParameters cngKeyCreationParameters = new CngKeyCreationParameters { ExportPolicy = CngExportPolicies.AllowPlaintextExport };
Expand Down Expand Up @@ -46,13 +48,11 @@ public static CngKey ToPublicKeyFromBlob(this byte[] publicBlob)
/// </summary>
public static byte[] GetSharedDhmSecret(this CngKey privateDhmKey, CngKey publicDhmKey, byte[] contextAppend = null, byte[] contextPrepend = null)
{
#if (NET462 || NETCOREAPP3_1)
using (var ecdh = new ECDiffieHellmanCng(privateDhmKey) { HashAlgorithm = CngAlgorithm.Sha384, SecretAppend = contextAppend, SecretPrepend = contextPrepend })
return ecdh.DeriveKeyMaterial(publicDhmKey);
#elif NETSTANDARD2_0
#if NETSTANDARD2_0
throw new PlatformNotSupportedException($"ECDiffieHellman is not supported on .NET Standard 2.0. Please reference \"{typeof(CngKeyExtensions).Assembly.GetName().Name}\" from .NET Framework or .NET Core for ECDiffieHellman support.");
#else
#error Unknown target
using (var ecdh = new ECDiffieHellmanCng(privateDhmKey) { HashAlgorithm = CngAlgorithm.Sha384, SecretAppend = contextAppend, SecretPrepend = contextPrepend })
return ecdh.DeriveKeyMaterial(publicDhmKey);
#endif
}// GetSharedDhmSecret()

Expand Down
10 changes: 7 additions & 3 deletions SecurityDriven.Inferno.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net462;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net8.0;netcoreapp3.1;net462;netstandard2.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<RootNamespace>SecurityDriven.Inferno</RootNamespace>
Expand Down Expand Up @@ -41,11 +41,15 @@
<Compile Remove="Mac\HMAC3.cs" />
</ItemGroup>

<ItemGroup>
<ItemGroup Condition="$(TargetFramework) == 'netstandard2.0' OR $(TargetFramework) == 'net462'">
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
<PackageReference Include="System.Security.Cryptography.Cng" Version="5.0.0" Condition="'$(TargetFramework)' != 'net462'" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework) == 'netstandard2.0' OR $(TargetFramework) == 'netcoreapp3.1'">
<PackageReference Include="System.Security.Cryptography.Cng" Version="5.0.0" />
<PackageReference Include="System.Formats.Asn1" Version="9.0.0" />
</ItemGroup>

</Project>