Export SetEncryptionMethod.

Allows creation of own header. For example UTF-8 file names by setting
bit 11 on header.
This commit is contained in:
Meik Kreyenkoetter 2018-06-11 15:58:11 +02:00
parent c5fb195ee3
commit 790e8f4b4e
1 changed files with 4 additions and 3 deletions

View File

@ -388,7 +388,7 @@ func encryptStream(key []byte, w io.Writer) (io.Writer, error) {
// data. The authcode will be written out in fileWriter.close(). // data. The authcode will be written out in fileWriter.close().
func newEncryptionWriter(w io.Writer, password passwordFn, fw *fileWriter, aesstrength byte) (io.Writer, error) { func newEncryptionWriter(w io.Writer, password passwordFn, fw *fileWriter, aesstrength byte) (io.Writer, error) {
keysize := aesKeyLen(aesstrength) keysize := aesKeyLen(aesstrength)
salt := make([]byte, keysize / 2) salt := make([]byte, keysize/2)
_, err := rand.Read(salt[:]) _, err := rand.Read(salt[:])
if err != nil { if err != nil {
return nil, errors.New("zip: unable to generate random salt") return nil, errors.New("zip: unable to generate random salt")
@ -437,7 +437,8 @@ func (h *FileHeader) writeWinZipExtra() {
h.Extra = append(h.Extra, buf[:]...) h.Extra = append(h.Extra, buf[:]...)
} }
func (h *FileHeader) setEncryptionMethod(enc EncryptionMethod) { // SetEncryptionMethod sets the encryption method.
func (h *FileHeader) SetEncryptionMethod(enc EncryptionMethod) {
h.encryption = enc h.encryption = enc
switch enc { switch enc {
case AES128Encryption: case AES128Encryption:
@ -478,6 +479,6 @@ func (w *Writer) Encrypt(name string, password string, enc EncryptionMethod) (io
Method: Deflate, Method: Deflate,
} }
fh.SetPassword(password) fh.SetPassword(password)
fh.setEncryptionMethod(enc) fh.SetEncryptionMethod(enc)
return w.CreateHeader(fh) return w.CreateHeader(fh)
} }