package com.xty.common

import com.tamsiree.rxkit.RxDataTool
import javax.crypto.Cipher
import javax.crypto.spec.SecretKeySpec

object AESCrypt {
    //AES加密
    val password="anyu1234anyu5678"

    fun encrypt(input:String): String{

        //初始化cipher对象
        val cipher = Cipher.getInstance("AES")
        // 生成密钥
        val keySpec: SecretKeySpec? = SecretKeySpec(password.toByteArray(),"AES")
        cipher.init(Cipher.ENCRYPT_MODE,keySpec)
        //加密
        val encrypt = cipher.doFinal(input.toByteArray())

        return  RxDataTool.bytes2HexString(encrypt)
    }

/*    //AES解密
    fun decrypt(input: String,password: String): String{

        //初始化cipher对象
        val cipher = Cipher.getInstance("AES")
        // 生成密钥
        val keySpec:SecretKeySpec? = SecretKeySpec(password.toByteArray(),"AES")
        cipher.init(Cipher.DECRYPT_MODE,keySpec)
        // 解密
        val encrypt = cipher.doFinal(Base64.getDecoder().decode(input.toByteArray()))
        //AES解密不需要用Base64解码
        val result = String(encrypt)

        return result
    }*/

}