package com.img.rabbit.utils


import android.util.Base64
import io.github.fastaes.FastAES

object AESpkcs7paddingUtil {

    /**
     * 编码格式
     */
    const val ENCODING = "utf-8"

    /**
     * AES解密
     *
     * @param encryptStr 加密后的密文
     * @param key        密钥
     * @return 源字符串
     * @throws Exception
     */
    @Throws(Exception::class)
    fun decryptNormal(encryptStr: String?, key: String): String {
        val sourceBytes = Base64.decode(encryptStr, Base64.NO_WRAP)
        val keyBytes = key.toByteArray(charset(ENCODING))
        val plain: ByteArray = FastAES.decrypt(sourceBytes, keyBytes, key.substring(0, 16).toByteArray(charset(ENCODING)))
        return String(plain)
    }
}

