Golang 1.2: Unzip password protected zip file?

后端 未结 3 1964
攒了一身酷
攒了一身酷 2021-01-05 02:07

Looking at the latest release (1.2) zip package - how can I unzip a file that was password protected (using 7zip, AES-256 encoding)? I don\'t see where/how to add in that i

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-05 02:16

    https://github.com/yeka/zip provides functionality to extract password protected zip file (AES & Zip Standard Encryption aka ZipCrypto).

    Below is an example how to use it:

    package main
    
    import (
        "os"
        "io"
        "github.com/yeka/zip"
    )
    
    func main() {
        file := "file.zip"
        password := "password"
        r, err := zip.OpenReader(file)
        if nil != err {
            panic(err)
        }
        defer r.Close()
    
        for _, f := range r.File {
            f.SetPassword(password)
            w, err := os.Create(f.Name)
            if nil != err {
                panic(err)
            }
            io.Copy(w, f)
            w.Close()
        }
    }
    

    The work is a fork from https://github.com/alexmullins/zip which add support for AES only.

提交回复
热议问题