Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET Changing password leaves the file(s) without password

Viewing 1 post (of 1 total)
  • Author
  • js
    Post count: 1
    #51208 |

    We are trying to simply change the passwords of files in existing ZIP files.
    In order to do so we apparently have to first unzip the files, change the password of the archive,
    and then zip the files again.

    When doing so with the below sample code the files are apparently added to the archive without a password at all.

    Can someone point us in the right direction to what we are doing wrong (why the password is not 1234) after running the code?

    And if there is a more efficient way to change passwords of existing files in a ZIP file we would also like to hear about this…

    Thanks for any help in advance!

    private void btnStart_Click(object sender, EventArgs e)
    ZipArchive zipArchive = new ZipArchive(new DiskFile(“D:\\Temp\\Logs\\Test1.zip”));
    AbstractFile originalFile = new ZippedFile(zipArchive.ZipFile, “Log.txt”);

    AbstractFile temporaryMemoryFile = new MemoryFile(“RAM_Disk”, “SomeName.txt”);

    //Set the original password for unzipping the original file
    zipArchive.DefaultDecryptionPassword = “12”;

    //Unzip the original file to the temporary memory file
    originalFile.CopyTo(temporaryMemoryFile, true);

    //Change the password for the archive to save the file with the new password
    zipArchive.DefaultDecryptionPassword = “1234”;

    //Overwrite the original file with the temporary file, which is the original file in unzipped condition
    temporaryMemoryFile.CopyTo(originalFile, true);

    //Now the original file in the archive is simply saved without any password at all!
    //All other existing files in the archive are still password protected as expected (with the original password)


Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.