Fork of Go's archive/zip to add reading/writing of password protected zip files.
Go to file
Meik Kreyenkoetter 38e38bf949 Merge branch 'master' into ownheader 2020-03-19 15:09:30 +01:00
testdata add test for failing corrupt input into flate 2015-10-29 23:12:02 -05:00
.gitignore Added initial support for reading pw protected files. 2015-10-29 16:14:19 -05:00
LICENSE Create LICENSE 2018-09-14 19:55:37 +07:00
README.md Fix typo in import statement 2018-03-25 12:40:52 +02:00
crypto.go Export SetEncryptionMethod. 2018-06-11 15:58:11 +02:00
crypto_test.go Fixed test error. 2018-06-11 15:57:19 +02:00
example_test.go Add encrypt & decrypt using zip standard encryption 2018-02-23 12:14:14 +07:00
reader.go Add encrypt & decrypt using zip standard encryption 2018-02-23 12:14:14 +07:00
reader_test.go defer authentication/buffering to Read not Open 2015-11-05 23:12:14 -06:00
register.go Initial commit and README.txt 2015-10-27 04:12:51 -05:00
struct.go Selectable Encryption Method 2018-02-23 12:14:14 +07:00
writer.go Change README to include example 2018-02-23 12:34:12 +07:00
writer_test.go Initial commit and README.txt 2015-10-27 04:12:51 -05:00
zip_test.go Initial commit and README.txt 2015-10-27 04:12:51 -05:00
zipcrypto.go Write CRC for Standard Zip Encryption 2018-02-23 12:14:14 +07:00
zipwriters.png Add password protected writing 2015-12-02 00:58:01 -06:00

README.md

This fork add support for Standard Zip Encryption.

The work is based on https://github.com/alexmullins/zip

Available encryption:

zip.StandardEncryption
zip.AES128Encryption
zip.AES192Encryption
zip.AES256Encryption

Warning

Zip Standard Encryption isn't actually secure. Unless you have to work with it, please use AES encryption instead.

Example Encrypt Zip

package main

import (
	"bytes"
	"io"
	"log"
	"os"

	"github.com/yeka/zip"
)

func main() {
	contents := []byte("Hello World")
	fzip, err := os.Create(`./test.zip`)
	if err != nil {
		log.Fatalln(err)
	}
	zipw := zip.NewWriter(fzip)
	defer zipw.Close()
	w, err := zipw.Encrypt(`test.txt`, `golang`, zip.AES256Encryption)
	if err != nil {
		log.Fatal(err)
	}
	_, err = io.Copy(w, bytes.NewReader(contents))
	if err != nil {
		log.Fatal(err)
	}
	zipw.Flush()
}

Example Decrypt Zip

package main

import (
	"fmt"
	"io/ioutil"
	"log"

	"github.com/yeka/zip"
)

func main() {
	r, err := zip.OpenReader("encrypted.zip")
	if err != nil {
		log.Fatal(err)
	}
	defer r.Close()

	for _, f := range r.File {
		if f.IsEncrypted() {
			f.SetPassword("12345")
		}

		r, err := f.Open()
		if err != nil {
			log.Fatal(err)
		}

		buf, err := ioutil.ReadAll(r)
		if err != nil {
			log.Fatal(err)
		}
		defer r.Close()

		fmt.Printf("Size of %v: %v byte(s)\n", f.Name, len(buf))
	}
}