-
Notifications
You must be signed in to change notification settings - Fork 0
/
PMKey.cs
37 lines (34 loc) · 898 Bytes
/
PMKey.cs
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
34
35
36
37
using System;
using AdiIRCAPI;
using Chaos.NaCl;
namespace AdiIRC_Encrypt {
public class PMKey : IDisposable {
private string user;
private byte[] myPrivKey;
public byte[] MyPublicKey {
get {
return MontgomeryCurve25519.GetPublicKey(myPrivKey);
}
}
private byte[] usersPubKey;
public byte[] UsersPubKey {
get { return usersPubKey; }
}
private byte[] sharedKey;
public byte[] SharedKey {
get { return sharedKey; }
}
public PMKey(string forUser) {
user = forUser;
myPrivKey = RNG.GetBytes(32);
}
public void SetUsersPublicKey(byte[] pubKey) {
usersPubKey = pubKey;
sharedKey = MontgomeryCurve25519.KeyExchange(usersPubKey, myPrivKey);
MontgomeryCurve25519.KeyExchangeOutputHashNaCl(sharedKey, 0);
}
public void Dispose() {
CryptoBytes.InternalWipe(myPrivKey, 0, myPrivKey.Length);
}
}
}