AES加密解密

aes
创建于:2021年03月01日
package aes

import (
    "encoding/base64"
    "fmt"
    "github.com/forgoer/openssl"
)

const key  = "abcdefgh87654321" // 16位字符串

// 加密
func Encrypt(src []byte) string {
    keyByte:=[]byte(key)
    dst , err := openssl.AesECBEncrypt(src, keyByte, openssl.PKCS7_PADDING)
    if err != nil{
        fmt.Println(err)
    }

    return base64.StdEncoding.EncodeToString(dst)
}

// 解密
func Decrypt(data string) (src []byte) {
    src, err := base64.StdEncoding.DecodeString(data)
    if err != nil{
        fmt.Println(err)
        return
    }

    keyByte:=[]byte(key)
    src , err = openssl.AesECBDecrypt(src, keyByte, openssl.PKCS7_PADDING)
    if err != nil{
        fmt.Println(err)
    }
    return
}