Quantcast
Channel: SharpDevelop Community
Viewing all articles
Browse latest Browse all 1764

Create tar file and set encryption and password similar to zipoutputstream

$
0
0

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


Viewing all articles
Browse latest Browse all 1764

Latest Images

Trending Articles



Latest Images