public static string SendMessage(string data, byte[] secretKey, byte[] publicKey) { var textBts = Encoding.UTF8.GetBytes(data); var nonce = GenerateNonce(); var message = Create(textBts, nonce, secretKey, publicKey); var messageToBase64 = Convert.ToBase64String(message); var nonceBase64 = Convert.ToBase64String(nonce); return(LZString.compressToBase64($"{messageToBase64}.{nonceBase64}")); }
public static string ReadMessage(string data, byte[] secretKey, byte[] publicKey) { var decrp = LZString.decompressFromBase64(data); var empt = decrp.Split('.'); if (empt.Length != 2) { throw new Exception("Data is not valid"); } var message = Convert.FromBase64String(empt[0]); var nonce = Convert.FromBase64String(empt[1]); var decryptedMessage = Open(message, nonce, secretKey, publicKey); return(Encoding.UTF8.GetString(decryptedMessage)); }