public string Decrypt(string message) { if (message.StartsWith("+OK ")) { message = message.Substring(4); } else if (message.StartsWith("mcps ")) { message = message.Substring(5); } else { return(message); } byte[] plainText; byte[] cipherText; if (message.StartsWith("*")) { cipherText = Convert.FromBase64String(message.Remove(0, 1)); plainText = CbcDecrypt(cipherText.Pad(BlockSize)); } else { cipherText = FishBase64.Decode(_encoding.GetBytes(message)); plainText = EcbDecrypt(cipherText.Pad(BlockSize)); } return(_encoding.GetString(plainText)); }
public string Encrypt(string message) { if (_mode == CipherMode.CBC) { byte[] enc = CbcEncrypt(_encoding.GetBytes(message).Pad(BlockSize)); return("+OK *" + Convert.ToBase64String(enc)); } else { byte[] enc = EcbEncrypt(_encoding.GetBytes(message).Pad(BlockSize)); return("+OK " + _encoding.GetString(FishBase64.Encode(enc))); } }