1 #region encrypt 2 protected byte[] Encrypt(string password) 3 { 4 //declare 5 byte[] buffer; 6 7 // buffer = Encoding.UTF8.GetBytes(password); 8 // password = Convert.ToBase64String(buffer, 0, buffer.Length); 9 buffer = Encoding.UTF8.GetBytes(password); 10 11 //return buffer; 12 13 MemoryStream ms = new MemoryStream(); 14 SymmetricAlgorithm sa ; 15 sa = RC2.Create(); 16 sa.Key = PasswordKey; 17 sa.IV = PasswordKey; 18 19 CryptoStream cs = new CryptoStream(ms, sa.CreateEncryptor(), CryptoStreamMode.Write); 20 21 try 22 { 23 for(int i = 0; i < buffer.Length; i++) 24 { 25 cs.WriteByte(buffer[i]); 26 } 27 } 28 finally 29 { 30 cs.Close(); 31 ms.Close(); 32 } 33 34 return ms.ToArray(); 35 } 36 #endregion