public byte[] EncryptMessage(string clientId, string msg, byte[] nonce) { if (_clientKeys.ContainsKey(clientId)) { var pair = _clientKeys[clientId]; return(TweetNaCl.CryptoBox(_utf8.GetBytes(msg), nonce, pair.PublicKey, pair.PrivateKey)); } return(null); }
public JsonBase DecryptMessage(byte[] message, byte[] nonce) { if (_pair == null) { return(null); } var data = TweetNaCl.CryptoBoxOpen(message, nonce, ClientPublicKey, _pair.PrivateKey); return(new JsonBase(JObject.Parse(_utf8.GetString(data)))); }
public JsonBase DecryptMessage(string clientId, byte[] message, byte[] nonce) { if (_clientKeys.ContainsKey(clientId)) { var pair = _clientKeys[clientId]; var data = TweetNaCl.CryptoBoxOpen(message, nonce, pair.PublicKey, pair.PrivateKey); return(new JsonBase(JObject.Parse(_utf8.GetString(data)))); } return(null); }
public KeyPair() { PrivateKey = new byte[TweetNaCl.BoxSecretKeyBytes]; PublicKey = TweetNaCl.CryptoBoxKeypair(PrivateKey); }
public static byte[] GenerateNonce(byte[] nonce) => TweetNaCl.Increment(nonce);
public byte[] EncryptMessage(string msg, byte[] nonce) { return(TweetNaCl.CryptoBox(_utf8.GetBytes(msg), nonce, ClientPublicKey, _pair.PrivateKey)); }
public static byte[] GenerateNonce(byte[] nonce) { return(TweetNaCl.Increment(nonce)); }