Skip to content
Merged
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
6 changes: 3 additions & 3 deletions sandbox/MicroBenchmark/NKeyBench.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using BenchmarkDotNet.Attributes;
using NATS.Client.Core;
using NATS.NKeys;

namespace MicroBenchmark;

Expand All @@ -17,8 +17,8 @@ public int NKeyCreate()
var result = 0;
for (var i = 0; i < Iter; i++)
{
var nkey = NKeys.FromSeed("SUAAVWRZG6M5FA5VRRGWSCIHKTOJC7EWNIT4JV3FTOIPO4OBFR5WA7X5TE");
result += nkey.PublicKey.Length;
using var kp = KeyPair.FromSeed("SUAAVWRZG6M5FA5VRRGWSCIHKTOJC7EWNIT4JV3FTOIPO4OBFR5WA7X5TE".AsSpan());
result += kp.GetPublicKey().Length;
}

return result;
Expand Down
39 changes: 0 additions & 39 deletions sandbox/MicroBenchmark/Sha512Bench.cs

This file was deleted.

16 changes: 9 additions & 7 deletions src/NATS.Client.Core/Internal/UserCredentials.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Security.Cryptography;
using System.Text;
using Microsoft.Extensions.Logging;
using NATS.Client.Core.NaCl;
using NATS.NKeys;

namespace NATS.Client.Core.Internal;

Expand Down Expand Up @@ -54,11 +53,11 @@ public UserCredentials(NatsAuthOpts authOpts)
if (seed == null || nonce == null)
return null;

using var kp = NKeys.FromSeed(seed);
var bytes = kp.Sign(Encoding.ASCII.GetBytes(nonce));
var sig = CryptoBytes.ToBase64String(bytes);
using var kp = KeyPair.FromSeed(seed.AsSpan());
var signature = new byte[64];
kp.Sign(Encoding.ASCII.GetBytes(nonce), signature);

return sig;
return Convert.ToBase64String(signature);
}

internal async Task AuthenticateAsync(ClientOpts opts, ServerInfo? info, NatsUri uri, TimeSpan timeout, CancellationToken cancellationToken)
Expand Down Expand Up @@ -99,7 +98,10 @@ internal async Task AuthenticateAsync(ClientOpts opts, ServerInfo? info, NatsUri
if (!string.IsNullOrEmpty(authCred.Secret))
{
seed = authCred.Secret;
opts.NKey = NKeys.PublicKeyFromSeed(seed);
using (var kp = KeyPair.FromSeed(seed.AsSpan()))
{
opts.NKey = kp.GetPublicKey();
}
}

break;
Expand Down
1 change: 1 addition & 0 deletions src/NATS.Client.Core/NATS.Client.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1"/>
<PackageReference Include="Microsoft.Extensions.Primitives" Version="6.0.0"/>
<PackageReference Include="NATS.NKeys" Version="1.0.1"/>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.10.48">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Loading
Loading