1
// Copyright 2010 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
5
// This code differs from the slides in that it handles errors.
18
func EncryptAndGzip(dstfile, srcfile string, key, iv []byte) error {
19
r, err := os.Open(srcfile)
24
w, err = os.Create(dstfile)
28
c, err := aes.NewCipher(key)
32
w = cipher.StreamWriter{S: cipher.NewOFB(c, iv), W: w}
33
w2, err := gzip.NewWriter(w)
38
_, err = io.Copy(w2, r)
42
func DecryptAndGunzip(dstfile, srcfile string, key, iv []byte) error {
43
f, err := os.Open(srcfile)
48
c, err := aes.NewCipher(key)
52
r := cipher.StreamReader{S: cipher.NewOFB(c, iv), R: f}
53
r2, err := gzip.NewReader(r)
57
w, err := os.Create(dstfile)
62
_, err = io.Copy(w, r2)
67
err := EncryptAndGzip(
76
err = DecryptAndGunzip(