2015-09-10 18:24:18 -04:00
|
|
|
package io
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/aes"
|
|
|
|
"crypto/cipher"
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
2015-09-17 17:26:09 -04:00
|
|
|
func NewAesDecryptReader(key []byte, iv []byte, reader io.Reader) (*CryptionReader, error) {
|
2015-09-10 18:24:18 -04:00
|
|
|
aesBlock, err := aes.NewCipher(key)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2015-09-12 14:36:21 -04:00
|
|
|
aesStream := cipher.NewCFBDecrypter(aesBlock, iv)
|
|
|
|
return NewCryptionReader(aesStream, reader), nil
|
2015-09-10 18:24:18 -04:00
|
|
|
}
|
|
|
|
|
2015-09-17 17:26:09 -04:00
|
|
|
func NewAesEncryptWriter(key []byte, iv []byte, writer io.Writer) (*CryptionWriter, error) {
|
2015-09-10 18:24:18 -04:00
|
|
|
aesBlock, err := aes.NewCipher(key)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2015-09-12 14:36:21 -04:00
|
|
|
aesStream := cipher.NewCFBEncrypter(aesBlock, iv)
|
|
|
|
return NewCryptionWriter(aesStream, writer), nil
|
2015-09-10 18:24:18 -04:00
|
|
|
}
|