diff options
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)); + } + } +} |