我想用C#来实现加密文件和文件夹.
有没有人知道加这个原理???

解决方案 »

  1.   

    我前面刚做查了一个         public static string Encrypt(string pToEncrypt, string sKey)
            {
                using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
                {
                    byte[] inputByteArray = Encoding.UTF8.GetBytes(pToEncrypt);
                    des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
                    des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
                    System.IO.MemoryStream ms = new System.IO.MemoryStream();
                    using (CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write))
                    {
                        cs.Write(inputByteArray, 0, inputByteArray.Length);
                        cs.FlushFinalBlock();
                        cs.Close();
                    }
                    string str = Convert.ToBase64String(ms.ToArray());
                    ms.Close();
                    return str;
                }
            }        public static string Decrypt(string pToDecrypt, string sKey)
            {
                byte[] inputByteArray = Convert.FromBase64String(pToDecrypt);
                using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
                {
                    des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
                    des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
                    System.IO.MemoryStream ms = new System.IO.MemoryStream();
                    using (CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write))
                    {
                        cs.Write(inputByteArray, 0, inputByteArray.Length);
                        cs.FlushFinalBlock();
                        cs.Close();
                    }
                    string str = Encoding.UTF8.GetString(ms.ToArray());
                    ms.Close();
                    return str;
                }
            }
      

  2.   

    1.利用windows系统特殊的保留文件名后缀,使文件夹无法打开和删除。 
    例如类似com1.{21ec2020-3aea-1069-a2dd-08002b30309d}等文件夹名称。 2.利用回收站特点,将文件夹保存在回收站,然后创建创建名为recycle或者RECYCLED的伪回收站。 3.直接将系统—文件夹的对应关系破坏, 
    在系统中留下一个没有文件实际地址的文件目录, 
    而在加密软件中则保存该文件夹的实际地址。 4、通过系统驻留程序监控被加密的文件夹,如果需打开,则提示输入密码,而实际上并没有对文件进行加密。