2010-06-08 17:00:04 -06:00
|
|
|
// Copyright 2010 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/aes"
|
2011-07-12 17:40:49 -06:00
|
|
|
"crypto/cipher"
|
2010-06-08 17:00:04 -06:00
|
|
|
"compress/gzip"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
func EncryptAndGzip(dstfile, srcfile string, key, iv []byte) {
|
2011-07-12 17:40:49 -06:00
|
|
|
r, _ := os.Open(srcfile)
|
2010-06-08 17:00:04 -06:00
|
|
|
var w io.WriteCloser
|
2011-07-12 17:40:49 -06:00
|
|
|
w, _ = os.Create(dstfile)
|
2010-06-08 17:00:04 -06:00
|
|
|
defer w.Close()
|
2011-07-12 17:40:49 -06:00
|
|
|
w, _ = gzip.NewWriter(w)
|
2010-06-08 17:00:04 -06:00
|
|
|
defer w.Close()
|
|
|
|
c, _ := aes.NewCipher(key)
|
2011-07-12 17:40:49 -06:00
|
|
|
io.Copy(cipher.StreamWriter{S: cipher.NewOFB(c, iv), W: w}, r)
|
2010-06-08 17:00:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
EncryptAndGzip("/tmp/passwd.gz", "/etc/passwd", make([]byte, 16), make([]byte, 16))
|
|
|
|
}
|