func (a *AESCBCHMAC) Encrypt(plaintext, additionalData []byte) ([]byte, error) {
	if len(plaintext) > maxInt-AESCBCIVSize {
		return nil, errors.New("aes_cbc_hmac: plaintext too long")
	}
	iv := a.newIV()
	cbcHMAC, err := josecipher.NewCBCHMAC(a.Key, aes.NewCipher)
	if err != nil {
		return nil, fmt.Errorf("aes_cbc_hmac: %w", err)
	}
	ciphertext := cbcHMAC.Seal(nil, iv, plaintext, additionalData)
	ciphertextAndIV := make([]byte, AESCBCIVSize+len(ciphertext))
	if n := copy(ciphertextAndIV, iv); n != AESCBCIVSize {
		return nil, fmt.Errorf("aes_cbc_hmac: failed to copy IV (copied %d/%d bytes)", n, AESCBCIVSize)
	}
	copy(ciphertextAndIV[AESCBCIVSize:], ciphertext)
	return ciphertextAndIV, nil
}
Encrypt encrypts plaintext using AES in CTR mode.
The resulting ciphertext consists of two parts:
(1) a random IV used for encryption and (2) the actual ciphertext.
package subtle
import (
	"crypto/aes"
	"errors"
	"fmt"
	"github.com/google/tink/go/subtle/random"
	josecipher "github.com/square/go-jose/v3/cipher"
)
type AESCBCHMAC struct {
	Key []byte
}
func NewAESCBCHMAC(key []byte) (*AESCBCHMAC, error) {
	keySize := uint32(len(key))
	if err := ValidateAESKeySizeForGoJose(keySize); err != nil {
		return nil, fmt.Errorf("aes_cbc_hmac: %w", err)
	}
	return &AESCBCHMAC{Key: key}, nil
}