我在編程方面頗爲新穎。爲了提示用戶輸入密碼來加密文件,我編寫了下面的代碼,但它在密碼長度爲8時才起作用,我能做什麼爲了接受任何數量的密碼字符?使用rijndael的加密
string pass = textBox2.Text.ToString();
string password = @"" + pass + "";
UnicodeEncoding UE = new UnicodeEncoding();
byte[] key = UE.GetBytes(password);
FileStream fsCrypt = new FileStream(@"c:\\users\\new", FileMode.Create);
name = fsCrypt.Name;
RijndaelManaged RMCrypto = new RijndaelManaged();
CryptoStream cs = new CryptoStream(fsCrypt,
RMCrypto.CreateEncryptor(key, key),
CryptoStreamMode.Write);
FileStream fsIn = new FileStream(filename, FileMode.Open);
int data;
while ((data = fsIn.ReadByte()) != -1)
cs.WriteByte((byte)data);
我有點用線不解:字符串密碼= @「」 +傳+「」;你想通過在字符串的每一端連接一個空字符串來實現什麼,從而產生一個相同的字符串。 – 2010-06-10 10:48:19