package yu_crypto

import (
	"crypto/aes"
	"crypto/cipher"
)

func AESCBCPKCS7En(src []byte, key []byte, iv []byte) []byte {
	block, _ := aes.NewCipher(key)
	ecb := cipher.NewCBCEncrypter(block, iv)
	content := make([]byte, 0, len(src)+block.BlockSize())
	content = append(content, src...)
	content = PKCS7Padding(content, block.BlockSize())
	crypted := make([]byte, len(content))
	ecb.CryptBlocks(crypted, content)
	return crypted
}

func AESCBCPKCS7De(src []byte, key []byte, iv []byte) []byte {
	block, _ := aes.NewCipher(key)
	ecb := cipher.NewCBCDecrypter(block, iv)
	decrypted := make([]byte, len(src))
	ecb.CryptBlocks(decrypted, src)
	return PKCS7Trimming(decrypted)
}
