还是文字Unicode编码问题,纯粹加密英文的时候会不会出错?

解决方案 »

  1.   

    我刚刚试过了。不光是中文、英文。不管原文件格式是unicode还是asci,都会出错。
    真的无语了。
      

  2.   

    private void btn_Encryp_Click(object sender, System.EventArgs e)
    {
    UnicodeEncoding en = new UnicodeEncoding();
    byte [] tempByte= en.GetBytes(this.textBox1.Text); MemoryStream ms = new MemoryStream();
    System.Security.Cryptography.CryptoStream cS = new CryptoStream(ms,iCT,CryptoStreamMode.Write);
    cS.Write(tempByte,0,tempByte.Length);
     cS.FlushFinalBlock();//这个很重要。
    this.textBox1.Clear();
    this.textBox1.Text = new String(en.GetChars(ms.ToArray()));
    }
    private void btn_Decryp_Click(object sender, System.EventArgs e)
    {

    UnicodeEncoding en = new UnicodeEncoding();
    byte[] tempByte = en.GetBytes(this.textBox1.Text);
    MemoryStream ms = new MemoryStream();
    System.Security.Cryptography.CryptoStream cS = new CryptoStream(ms,this.iCTD,CryptoStreamMode.Write);
    cS.Write(tempByte,0,tempByte.Length);
     cS.FlushFinalBlock();//这个很重要。
    this.textBox1.Clear();
    this.textBox1.Text = en.GetString(ms.ToArray());
    this.btn_Decryp .Enabled = false;
    this.btn_Encryp .Enabled = true;

    }
      

  3.   

    谢谢楼上的,不过试过了,在FlushFinalBlock()时出错了:内存流不可扩展;
    点解啊?