mirror of https://github.com/v2ray/v2ray-core
comments
parent
347ae8fd75
commit
0040881b84
|
@ -5,11 +5,15 @@ import (
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 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 {
|
func NewAesDecryptionStream(key []byte, iv []byte) cipher.Stream {
|
||||||
aesBlock, _ := aes.NewCipher(key)
|
aesBlock, _ := aes.NewCipher(key)
|
||||||
return cipher.NewCFBDecrypter(aesBlock, iv)
|
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 {
|
func NewAesEncryptionStream(key []byte, iv []byte) cipher.Stream {
|
||||||
aesBlock, _ := aes.NewCipher(key)
|
aesBlock, _ := aes.NewCipher(key)
|
||||||
return cipher.NewCFBEncrypter(aesBlock, iv)
|
return cipher.NewCFBEncrypter(aesBlock, iv)
|
||||||
|
|
|
@ -6,6 +6,8 @@ import (
|
||||||
"github.com/v2ray/v2ray-core/common/crypto/internal"
|
"github.com/v2ray/v2ray-core/common/crypto/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewChaCha20Stream creates a new Chacha20 encryption/descryption stream based on give key and IV.
|
||||||
|
// Caller must ensure the length of key is 32 bytes, and length of IV is either 8 or 12 bytes.
|
||||||
func NewChaCha20Stream(key []byte, iv []byte) cipher.Stream {
|
func NewChaCha20Stream(key []byte, iv []byte) cipher.Stream {
|
||||||
return internal.NewChaCha20Stream(key, iv, 20)
|
return internal.NewChaCha20Stream(key, iv, 20)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue