Skip to content
/ zip Public
forked from alexmullins/zip

Fork of Go's archive/zip to add reading/writing of password protected zip files.

License

Notifications You must be signed in to change notification settings

yeka/zip

This branch is 14 commits ahead of, 4 commits behind alexmullins/zip:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

03d6312 · Nov 16, 2023

History

56 Commits
Oct 30, 2015
Oct 29, 2015
Sep 14, 2018
Mar 25, 2018
Jun 11, 2018
Jun 11, 2018
Feb 23, 2018
Feb 23, 2018
Nov 6, 2015
Oct 27, 2015
Feb 23, 2018
Feb 23, 2018
Oct 27, 2015
Oct 27, 2015
Feb 23, 2018
Dec 2, 2015

Repository files navigation

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))
	}
}

About

Fork of Go's archive/zip to add reading/writing of password protected zip files.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%