Beispiel #1
0
 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);
 }
Beispiel #2
0
        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))));
        }
Beispiel #3
0
 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);
 }
Beispiel #4
0
 public KeyPair()
 {
     PrivateKey = new byte[TweetNaCl.BoxSecretKeyBytes];
     PublicKey  = TweetNaCl.CryptoBoxKeypair(PrivateKey);
 }
Beispiel #5
0
 public static byte[] GenerateNonce(byte[] nonce) => TweetNaCl.Increment(nonce);
Beispiel #6
0
 public byte[] EncryptMessage(string msg, byte[] nonce)
 {
     return(TweetNaCl.CryptoBox(_utf8.GetBytes(msg), nonce, ClientPublicKey, _pair.PrivateKey));
 }
Beispiel #7
0
 public static byte[] GenerateNonce(byte[] nonce)
 {
     return(TweetNaCl.Increment(nonce));
 }