mirror of
https://github.com/amnezia-vpn/amneziawg-windows-client.git
synced 2026-05-17 08:15:44 +03:00
34 lines
949 B
C#
34 lines
949 B
C#
/* SPDX-License-Identifier: MIT
|
|
*
|
|
* Copyright (C) 2019-2022 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));
|
|
}
|
|
}
|
|
}
|