예제 #1
0
        public static void Make_TAR(string What, string Where)
        {
            string        Out_TAR         = Path.GetFileNameWithoutExtension(Where) + ".tar";
            string        Out_MD5         = Path.GetFileNameWithoutExtension(Where) + ".tar.md5";
            Stream        fs              = new FileStream(Out_MD5, FileMode.Create);
            StringBuilder sb              = new StringBuilder();
            MD5           MD5_Hash_Engine = new MD5CryptoServiceProvider();

            Console.WriteLine("Creating: " + Out_MD5 + " .....");
            TarArchive TA = TarArchive.CreateOutputTarArchive(fs);
            TarEntry   TE = TarEntry.CreateEntryFromFile(What);

            TE.SetIds(0, 0);
            TE.SetNames(string.Empty, string.Empty);
            TE.TarHeader.Mode = 420;
            TA.WriteEntry(TE, true);
            TA.Close();
            fs.Close();
            Stream hash = new FileStream(Out_MD5, FileMode.Open);

            byte[] TAR_MD5_Hash = MD5_Hash_Engine.ComputeHash(hash);
            for (int i = 0; i < TAR_MD5_Hash.Length; i++)
            {
                sb.Append(TAR_MD5_Hash[i].ToString("X2"));
            }
            byte[] Final_Hash = Encoding.ASCII.GetBytes(sb.ToString().ToLower() + Convert.ToChar(0x20).ToString() + Convert.ToChar(0x20).ToString() + Out_TAR + Convert.ToChar("\n").ToString());
            Console.WriteLine("MD5 for " + Out_MD5 + " is " + sb.ToString().ToLower());
            hash.Write(Final_Hash, 0, Final_Hash.Length);
            hash.Close();
        }