SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Create tar file and set encryption and password similar to zipoutputstream

Last post 12-15-2016 11:33 PM by rxdevarasett. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 12-15-2016 11:33 PM

    Create tar file and set encryption and password similar to zipoutputstream

    Hello Experts

    I am working on Creating a new tar file using taroutputstream from existing tar file. I am using SharpZipLib version 0.86.0.518

    Currently there is no password or encryption set to the tar file. I need to encrypt and set password to the new tar file.

    I reviewed previous user forums and found some info related to encryption and password for zipoutputstream but no info on how to encrypt and set password for Tar file. 

    I appreciate your great help!!!

    Following is the sample code:

            private void CreateTar(string pWritePath, string pReadPath)
            {
                using (TarInputStream tarInputStream = new TarInputStream(File.OpenRead(pReadPath)))
                {
                    using (TarOutputStream tarOutputStream = new TarOutputStream(File.Create(pWritePath)))
                    {
                        TarEntry curEntry;

                        while ((curEntry = tarInputStream.GetNextEntry()) != null)
                        {
                            TarEntry newEntry = new TarEntry(curEntry.TarHeader);
                            newEntry.Name = curEntry.Name;
                            newEntry.Size = curEntry.Size;
                            newEntry.ModTime = curEntry.ModTime;
                            tarOutputStream.PutNextEntry(newEntry);

                            int size = 2048;
                            byte[ buffer = new byte[size];

                            while (size > 0)
                            {
                                size = tarInputStream.Read(buffer, 0, size);

                                if (size > 0)
                                    tarOutputStream.Write(buffer, 0, size);
                            }

                            tarOutputStream.CloseEntry();
                        }
                    }
                }

                File.Delete(pReadPath);
            }

    Thanks

Page 1 of 1 (1 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.