aes.go 691 B

1234567891011121314151617181920
  1. package crypto
  2. import (
  3. "crypto/aes"
  4. "crypto/cipher"
  5. )
  6. // NewAesDecryptionStream creates a new AES encryption stream based on given key and IV.
  7. // Caller must ensure the length of key and IV is either 16, 24 or 32 bytes.
  8. func NewAesDecryptionStream(key []byte, iv []byte) cipher.Stream {
  9. aesBlock, _ := aes.NewCipher(key)
  10. return cipher.NewCFBDecrypter(aesBlock, iv)
  11. }
  12. // NewAesEncryptionStream creates a new AES description stream based on given key and IV.
  13. // Caller must ensure the length of key and IV is either 16, 24 or 32 bytes.
  14. func NewAesEncryptionStream(key []byte, iv []byte) cipher.Stream {
  15. aesBlock, _ := aes.NewCipher(key)
  16. return cipher.NewCFBEncrypter(aesBlock, iv)
  17. }