1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00
v2fly/io/aes.go

28 lines
594 B
Go
Raw Normal View History

2015-09-10 18:24:18 -04:00
package io
import (
"crypto/aes"
"crypto/cipher"
"io"
)
func NewAesDecryptReader(key []byte, iv []byte, reader io.Reader) (io.Reader, error) {
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
}
func NewAesEncryptWriter(key []byte, iv []byte, writer io.Writer) (io.Writer, error) {
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
}