diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-01-04 16:26:47 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-01-21 15:26:07 +0100 |
commit | e9ed04e8ba4f3bee171938a435d70b2f2302f6a8 (patch) | |
tree | 6d169de5dd2a34041e40836040e8e1d994500a14 /embeddable-dll-service/csharp/TunnelDll/Keypair.cs | |
parent | locales: sync with crowdin (diff) | |
download | wireguard-windows-e9ed04e8ba4f3bee171938a435d70b2f2302f6a8.tar.xz wireguard-windows-e9ed04e8ba4f3bee171938a435d70b2f2302f6a8.zip |
embeddable-dll-service: add more robust example for .NET 5
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'embeddable-dll-service/csharp/TunnelDll/Keypair.cs')
-rw-r--r-- | embeddable-dll-service/csharp/TunnelDll/Keypair.cs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/embeddable-dll-service/csharp/TunnelDll/Keypair.cs b/embeddable-dll-service/csharp/TunnelDll/Keypair.cs new file mode 100644 index 00000000..146d56e0 --- /dev/null +++ b/embeddable-dll-service/csharp/TunnelDll/Keypair.cs @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (C) 2019-2021 WireGuard LLC. All Rights Reserved. + */ + +using System; +using System.Runtime.InteropServices; + +namespace Tunnel +{ + public class Keypair + { + public readonly string Public; + public readonly string Private; + + public Keypair(string pub, string priv) + { + Public = pub; + Private = priv; + } + + [DllImport("tunnel.dll", EntryPoint = "WireGuardGenerateKeypair", CallingConvention = CallingConvention.Cdecl)] + private static extern bool WireGuardGenerateKeypair(byte[] publicKey, byte[] privateKey); + + public static Keypair Generate() + { + var publicKey = new byte[32]; + var privateKey = new byte[32]; + WireGuardGenerateKeypair(publicKey, privateKey); + return new Keypair(Convert.ToBase64String(publicKey), Convert.ToBase64String(privateKey)); + } + } +} |