golang.zx2c4.com/wireguard/windows@v0.5.4-0.20230123132234-dcc0eb72a04b/embeddable-dll-service/csharp/TunnelDll/Keypair.cs (about) 1 /* SPDX-License-Identifier: MIT 2 * 3 * Copyright (C) 2019-2022 WireGuard LLC. All Rights Reserved. 4 */ 5 6 using System; 7 using System.Runtime.InteropServices; 8 9 namespace Tunnel 10 { 11 public class Keypair 12 { 13 public readonly string Public; 14 public readonly string Private; 15 16 public Keypair(string pub, string priv) 17 { 18 Public = pub; 19 Private = priv; 20 } 21 22 [DllImport("tunnel.dll", EntryPoint = "WireGuardGenerateKeypair", CallingConvention = CallingConvention.Cdecl)] 23 private static extern bool WireGuardGenerateKeypair(byte[] publicKey, byte[] privateKey); 24 25 public static Keypair Generate() 26 { 27 var publicKey = new byte[32]; 28 var privateKey = new byte[32]; 29 WireGuardGenerateKeypair(publicKey, privateKey); 30 return new Keypair(Convert.ToBase64String(publicKey), Convert.ToBase64String(privateKey)); 31 } 32 } 33 }