func AesEncrypt(plainText []byte, key string, iv ...string) (crypted []byte,
	err error) {
	var k []byte
	var block cipher.Block
	if len(iv) > 0 {
		k = String2Bytes(iv[0])
		block, err = aes.NewCipher(String2Bytes(key))
	} else {
		k = assKeyPadding(key)
		block, err = aes.NewCipher(k)
	}
	if err == nil {
		blockSize := block.BlockSize()
		plainText = PKCS7Padding(plainText, blockSize)
		blocMode := cipher.NewCBCEncrypter(block, k[:blockSize])
		crypted = make([]byte, len(plainText))
		blocMode.CryptBlocks(crypted, plainText)
	}
	return
}
AesEncrypt aes encryption
package zstring
import (
	"bytes"
	"crypto/aes"
	"crypto/cipher"
	"errors"
	"fmt"
	"strings"
)
func assKeyPadding(key string) []byte {
	k := String2Bytes(key)
	l := len(k)
	switch l {
	case 16, 24, 32:
		return k
	default:
		if l < 16 {
			return append(k, String2Bytes(strings.Repeat(" ", 16-l))...)
		} else if l < 24 {
			return append(k, String2Bytes(strings.Repeat(" ", 24-l))...)
		} else if l < 32 {
			return append(k, String2Bytes(strings.Repeat(" ", 32-l))...)
		}
		return k[0:32]
	}
}
func PKCS7Padding(ciphertext []byte, blockSize int) []byte {
	padding := blockSize - len(ciphertext)%blockSize
	pad := bytes.Repeat([]byte{byte(padding)}, padding)
	return append(ciphertext, pad...)
}
func PKCS7UnPadding(origData []byte) ([]byte, error) {
	length := len(origData)
	if length == 0 {
		return nil, errors.New("encryption string error")
	} else {
		u := int(origData[length-1])
		return origData[:(length - u)], nil
	}
}