summaryrefslogtreecommitdiff
path: root/doc/talks/io2010/encrypt.go
diff options
context:
space:
mode:
Diffstat (limited to 'doc/talks/io2010/encrypt.go')
-rw-r--r--doc/talks/io2010/encrypt.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/doc/talks/io2010/encrypt.go b/doc/talks/io2010/encrypt.go
new file mode 100644
index 000000000..e5ab3fc59
--- /dev/null
+++ b/doc/talks/io2010/encrypt.go
@@ -0,0 +1,28 @@
+// 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"
+ "crypto/block"
+ "compress/gzip"
+ "io"
+ "os"
+)
+
+func EncryptAndGzip(dstfile, srcfile string, key, iv []byte) {
+ r, _ := os.Open(srcfile, os.O_RDONLY, 0)
+ var w io.WriteCloser
+ w, _ = os.Open(dstfile, os.O_WRONLY|os.O_CREATE, 0666)
+ defer w.Close()
+ w, _ = gzip.NewDeflater(w)
+ defer w.Close()
+ c, _ := aes.NewCipher(key)
+ io.Copy(block.NewCBCEncrypter(c, iv, w), r)
+}
+
+func main() {
+ EncryptAndGzip("/tmp/passwd.gz", "/etc/passwd", make([]byte, 16), make([]byte, 16))
+}