如题,注意是文件夹,不是文件。不能利用rar工具。
谢谢!

解决方案 »

  1.   


     #1楼 得分:20回复于:2008-07-22 18:00:31一些简单的加解密
    C# code
    public static void Encrypt(string pathIn, string pathOut, string password)
            {
                try
                {
                    byte[] iv = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
                    byte[] key = System.Text.Encoding.UTF8.GetBytes(password);
                    System.IO.FileStream fs = new FileStream(pathIn, FileMode.Open, FileAccess.Read);
                    System.IO.FileStream outfs = new FileStream(pathOut, FileMode.OpenOrCreate, FileAccess.Write);
                    outfs.SetLength(0);
                    byte[] myBytes = new byte[100];
                    long myInLength = 0;
                    long myLength = fs.Length;
                    System.Security.Cryptography.DESCryptoServiceProvider dsp = new DESCryptoServiceProvider();
                    System.Security.Cryptography.CryptoStream cs = new CryptoStream(outfs, dsp.CreateEncryptor(key, iv), CryptoStreamMode.Write);
                    while (myInLength < myLength)
                    {
                        int myLen = fs.Read(myBytes, 0, 100);
                        cs.Write(myBytes, 0, myLen);
                        myInLength += myLen;
                    }
                    cs.Close();
                    fs.Close();
                    outfs.Close();
                }
                catch (IOException ioex)
                {
                    Log.debug("Encrypt(pathIn, pathOut, password): " + ioex.Message + "\r\nSource:" + ioex.Source + "\r\nStackTrace:" + ioex.StackTrace);
                }
            }        public static void Decrypt(string pathIn, string pathOut, string password)
            {
                try
                {
                    System.IO.FileStream fs = new FileStream(pathIn, FileMode.Open, FileAccess.Read);
                    System.IO.FileStream outfs = new FileStream(pathOut, FileMode.OpenOrCreate, FileAccess.Write);
                    outfs.SetLength(0);
                    long myLength = fs.Length;
                    long myInLength = 0;
                    byte[] iv = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
                    byte[] key = System.Text.Encoding.UTF8.GetBytes(password);
                    System.Security.Cryptography.DESCryptoServiceProvider dsp = new DESCryptoServiceProvider();
                    System.Security.Cryptography.CryptoStream cs = new CryptoStream(outfs, dsp.CreateDecryptor(key, iv), CryptoStreamMode.Write);
                    byte[] myBytes = new byte[100];
                    while (myInLength < myLength)
                    {
                        int myLen = fs.Read(myBytes, 0, 100);
                        cs.Write(myBytes, 0, myLen);
                        myInLength += myLen;
                    }
                    cs.Close();
                    fs.Close();
                    outfs.Close();
                }
                catch (IOException ioex)
                {
                    Log.debug("Dncrypt(pathIn, pathOut, password): " + ioex.Message + "\r\nSource:" + ioex.Source + "\r\nStackTrace:" + ioex.StackTrace);
                }
            }        public static string EncryptBy16MD5(string strProclaimed)
            {
                MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
                string strCryptograph = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(strProclaimed)), 4, 8);
                return strCryptograph;
            }        /// <summary>
            /// md5 32位加密
            /// </summary>
            /// <param name="strProclaimed">明文</param>
            /// <returns>密文</returns>
            public static string EncryptBy32MD5(string strProclaimed)
            {
                MD5 md5 = MD5.Create();
                string strCryptograph = "";
                byte[] bytCode = md5.ComputeHash(Encoding.UTF8.GetBytes(strProclaimed));
                for (int i = 0; i < bytCode.Length; i++)
                {
                    // 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符 
                    strCryptograph = strCryptograph + bytCode[i].ToString("x");
                }
                return strCryptograph;
            }
      

  2.   

    http://topic.csdn.net/u/20101126/10/f55f645f-cd76-4c3c-8cc7-0196d7bf8d09.html
      

  3.   


    这个加密文件可以,文件夹不行。。
    System.IO.FileStream fs = new FileStream(pathIn, FileMode.Open, FileAccess.Read);
    会出异常!