Encryption using rijndael

Posted by user363295 on Stack Overflow See other posts from Stack Overflow or by user363295
Published on 2010-06-10T10:01:17Z Indexed on 2010/06/10 10:02 UTC
Read the original article Hit count: 278

Filed under:

Hi all. I'm quite new in programming .I wrote the below code in order to prompt the user for a password to encrypting a file, But it just work when the length of password is 8, What can I do on order to accepting any number of characters for the password?

 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);

© Stack Overflow or respective owner

Related posts about c#