1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-04 21:15:24 +00:00
v2fly/common/crypto/aes.go

25 lines
757 B
Go
Raw Normal View History

2015-11-03 20:26:16 +00:00
package crypto
import (
"crypto/aes"
"crypto/cipher"
2017-04-28 12:48:23 +00:00
"v2ray.com/core/common"
2015-11-03 20:26:16 +00:00
)
2016-07-26 19:21:22 +00:00
// 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.
2016-02-25 20:50:10 +00:00
func NewAesDecryptionStream(key []byte, iv []byte) cipher.Stream {
2016-12-21 14:37:16 +00:00
aesBlock, err := aes.NewCipher(key)
2017-04-28 12:48:23 +00:00
common.Must(err)
2016-02-25 20:50:10 +00:00
return cipher.NewCFBDecrypter(aesBlock, iv)
2015-11-03 20:26:16 +00:00
}
2016-07-26 19:21:22 +00:00
// 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.
2016-02-25 20:50:10 +00:00
func NewAesEncryptionStream(key []byte, iv []byte) cipher.Stream {
2016-12-21 14:37:16 +00:00
aesBlock, err := aes.NewCipher(key)
2017-04-28 12:48:23 +00:00
common.Must(err)
2016-02-25 20:50:10 +00:00
return cipher.NewCFBEncrypter(aesBlock, iv)
2015-11-03 20:26:16 +00:00
}