mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
606 B
28 lines
606 B
9 years ago
|
package io
|
||
|
|
||
|
import (
|
||
|
"crypto/aes"
|
||
|
"crypto/cipher"
|
||
|
"io"
|
||
|
)
|
||
|
|
||
9 years ago
|
func NewAesDecryptReader(key []byte, iv []byte, reader io.Reader) (*CryptionReader, error) {
|
||
9 years ago
|
aesBlock, err := aes.NewCipher(key)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
9 years ago
|
aesStream := cipher.NewCFBDecrypter(aesBlock, iv)
|
||
|
return NewCryptionReader(aesStream, reader), nil
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
func NewAesEncryptWriter(key []byte, iv []byte, writer io.Writer) (*CryptionWriter, error) {
|
||
9 years ago
|
aesBlock, err := aes.NewCipher(key)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
9 years ago
|
aesStream := cipher.NewCFBEncrypter(aesBlock, iv)
|
||
|
return NewCryptionWriter(aesStream, writer), nil
|
||
9 years ago
|
}
|