Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Password zip is inconsisent #873

Open
HashPong opened this issue Jul 24, 2024 · 0 comments
Open

Password zip is inconsisent #873

HashPong opened this issue Jul 24, 2024 · 0 comments

Comments

@HashPong
Copy link

Describe the bug

Only passwords with length up to 98 seem to work, if i use 99 and i even copy/paste the password directly unzipping the archive using 7zip does not work. how come?

Seems a bit random and not sure if it would be safe for db backups in this case.

private static async Task CreateBackup(string zipFile, string pgDumpArgs)
{
    ProcessStartInfo processInfo = new()
    {
        FileName = @"C:\Program Files\PostgreSQL\16\bin\pg_dump.exe",
        Arguments = pgDumpArgs,
        RedirectStandardOutput = true,
        RedirectStandardError = true, // Capture error output
        UseShellExecute = false,
        CreateNoWindow = true
    };

    using Process process = Process.Start(processInfo);
    if (process == null)
    {
        Console.WriteLine("Failed to start pg_dump process.");
        return;
    }

    using (FileStream fsOut = File.Create(zipFile))
    using (ZipOutputStream zipStream = new(fsOut))
    {
        zipStream.SetLevel(3); // 0-9, 9 being the highest level of compression
        zipStream.Password = "z4KpjH+}H9H*g3K3Jb-9}M^jnMN^-!Zs+8UZ3sfxWg5T~@ZHJ:Eoz!AFNMwdf!g_2QpX#)}4WKwHLL%C?s1BB*wx%:cia0j=m7.W";
        zipStream.UseZip64 = UseZip64.On; // Set to AsNeeded if you need Zip64

        ZipEntry newEntry = new ZipEntry($"backup_{DateTime.Now:yyyyMMdd_HHmmss}.backup")
        {
            DateTime = DateTime.Now,
            AESKeySize = 256 // AES-256 encryption
        };

        zipStream.PutNextEntry(newEntry);

        var outputTask = process.StandardOutput.BaseStream.CopyToAsync(zipStream);
        var errorTask = process.StandardError.ReadToEndAsync();

        await Task.WhenAll(outputTask, errorTask);
        zipStream.CloseEntry();

        string errorOutput = await errorTask;

        if (!string.IsNullOrEmpty(errorOutput))
        {
            Console.WriteLine($"pg_dump reported the following errors:\n{errorOutput}");
        }
    }

    await process.WaitForExitAsync();

    if (process.ExitCode != 0)
    {
        Console.WriteLine($"pg_dump failed with exit code {process.ExitCode}");
    }
    else
    {
        Console.WriteLine($"{zipFile} Database backup successfully completed.");
    }
}

Reproduction Code

No response

Steps to reproduce

zip zip

Expected behavior

work

Operating System

Windows

Framework Version

Other

Tags

No response

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant