blob: 17a0a8765aa648fc6b85a8fb99eb311670b82b57 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
/* SPDX-License-Identifier: MIT
*
* Copyright (C) 2019-2020 WireGuard LLC. All Rights Reserved.
*/
using System;
using System.Runtime.InteropServices;
namespace Tunnel
{
public class Keypair
{
public readonly string Public;
public readonly string Private;
private 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));
}
}
}
|