diff --git a/aes.go b/aes.go index bb807c10..ccd9e5f8 100644 --- a/aes.go +++ b/aes.go @@ -46,11 +46,15 @@ func aesCtrStep(offset int64, enc *TransparentEncryptionInfo, b []byte) ([]byte, return nil, err } - block, err := aes.NewCipher(enc.key) - if err != nil { - return nil, err + if enc.cipher == nil { + cipher, err := aes.NewCipher(enc.key) + if err != nil { + return nil, err + } + enc.cipher = cipher } - stream := cipher.NewCTR(block, iv) + + stream := cipher.NewCTR(enc.cipher, iv) padding := offset % aes.BlockSize if padding > 0 { diff --git a/file_reader.go b/file_reader.go index 460a25d8..131d9a5d 100644 --- a/file_reader.go +++ b/file_reader.go @@ -1,6 +1,7 @@ package hdfs import ( + "crypto/cipher" "crypto/md5" "errors" "fmt" @@ -36,8 +37,9 @@ type FileReader struct { // A TransparentEncryptionInfo is a key and iv to encrypt or decrypt file data type TransparentEncryptionInfo struct { - key []byte - iv []byte + key []byte + iv []byte + cipher cipher.Block } // Open returns an FileReader which can be used for reading.