string cipherData;
byte[] cipherbytes;
byte[] plainbytes;
byte[] plainbytes2;
byte[] plainkey;
SymmetricAlgorithm desObj;
private void button1_Click(object sender, EventArgs e)
{
cipherData = textBox_Plain_text.Text;
plainbytes = Encoding.ASCII.GetBytes(cipherData);
plainkey = Encoding.ASCII.GetBytes("123456789abcdef");
desObj.Key = plainkey;
// choose other appropriate modes (CBC, CFB, CTS, ECB, OFB)
desObj.Mode = CipherMode.CBC;
desObj.Padding = PaddingMode.PKCS7;
System.IO.MemoryStream ms = new System.IO.MemoryStream();
CryptoStream cs = new CryptoStream(ms, desObj.CreateEncryptor(), new CryptoStreamMode());
cs.Write(plainbytes, 0, plainbytes.Length);
cs.Close;
cipherbytes = ms.ToArray();
ms.Close;
textBox_Encrypted_text.Text = Encoding.ASCII.GetString(cipherbytes);
}
error :Only assignment, call, increment, decrement, and new object expressions can be used as a statement.編譯錯誤:只有轉讓,電話,遞增,遞減和新對象表達式可以用作聲明
而究竟在何處是錯誤?請提供[mcve],清楚說明錯誤的位置。 –
看起來你在'.Close'之後丟失了括號。應該是'.Close()',因爲它是方法調用。 –
你留下幾個未處理的一次性用品。 Encoding.UTF8是比.ASCII更好的選擇 –