'use client'
import CryptoJS from 'crypto-js'

const ENCRYPTION_KEY = process.env.NEXT_PUBLIC_APP_ENCRYPTION_KEY ?? '' // Replace with a secure key

export const encrypt = (data: string): string => {
    return CryptoJS.AES.encrypt(data, ENCRYPTION_KEY).toString()
}

export const decrypt = (cipherText: string): string | any => {
    try {
        const bytes = CryptoJS.AES.decrypt(cipherText, ENCRYPTION_KEY)
        return bytes.toString(CryptoJS.enc.Utf8)
    } catch {
        return ''
    }
}
