mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-11-05 01:38:24 -05:00
28 lines
586 B
Go
28 lines
586 B
Go
|
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
|
||
|
}
|
||
|
|
||
|
aesMode := cipher.NewCBCDecrypter(aesBlock, iv)
|
||
|
return NewCryptionReader(aesMode, reader), nil
|
||
|
}
|
||
|
|
||
|
func NewAesEncryptWriter(key []byte, iv []byte, writer io.Writer) (io.Writer, error) {
|
||
|
aesBlock, err := aes.NewCipher(key)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
aesMode := cipher.NewCBCEncrypter(aesBlock, iv)
|
||
|
return NewCryptionWriter(aesMode, writer), nil
|
||
|
}
|