public string Base64Encode(string data) { return Convert.ToBase64String(Encoding.UTF8.GetBytes(data)); } public string Base64Decode(string data) { try { return Encoding.UTF8.GetString(Convert.FromBase64String(data)); } catch { // you can replace this with string.Empty if you'd prefer // or you could add a MessageBox.Show call return null; } }