// src/main/kotlin/util/AesCrypto.kt
package util

import java.util.Base64
import javax.crypto.Cipher
import javax.crypto.spec.IvParameterSpec
import javax.crypto.spec.SecretKeySpec

object AesCrypto {
    fun decrypt(cipherText: String, key: String, iv: String): String {
        return try {
            val keySpec = SecretKeySpec(key.toByteArray(Charsets.UTF_8), "AES")
            val ivSpec = IvParameterSpec(iv.toByteArray(Charsets.UTF_8))

            val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
            cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec)

            val decodedBytes = Base64.getDecoder().decode(cipherText)
            val decryptedBytes = cipher.doFinal(decodedBytes)

            String(decryptedBytes, Charsets.UTF_8)
        } catch (e: Exception) {
            "복호화 실패: ${e.message}"
        }
    }
}