1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-02 12:05:23 +00:00
v2fly/common/crypto/aes.go
Darien Raymond 693702350d
refactor
2017-04-28 14:48:23 +02:00

25 lines
757 B
Go

package crypto
import (
"crypto/aes"
"crypto/cipher"
"v2ray.com/core/common"
)
// NewAesDecryptionStream creates a new AES encryption stream based on given key and IV.
// Caller must ensure the length of key and IV is either 16, 24 or 32 bytes.
func NewAesDecryptionStream(key []byte, iv []byte) cipher.Stream {
aesBlock, err := aes.NewCipher(key)
common.Must(err)
return cipher.NewCFBDecrypter(aesBlock, iv)
}
// NewAesEncryptionStream creates a new AES description stream based on given key and IV.
// Caller must ensure the length of key and IV is either 16, 24 or 32 bytes.
func NewAesEncryptionStream(key []byte, iv []byte) cipher.Stream {
aesBlock, err := aes.NewCipher(key)
common.Must(err)
return cipher.NewCFBEncrypter(aesBlock, iv)
}