<?php

namespace App\Security;

class AESUtils {
    
    private const AES_ALGORITHM = 'aes-128-ecb';
    
    // Function to encrypt data using AES
    public static function encrypt($data, $key) {     
        $cipherText = openssl_encrypt($data, self::AES_ALGORITHM, $key, OPENSSL_RAW_DATA);
        return base64_encode($cipherText);
    }
    
    // Function to decrypt data using AES
    public static function decrypt($encryptedData, $key) {
        $decodedData = base64_decode($encryptedData);        
        return openssl_decrypt($decodedData, self::AES_ALGORITHM, $key, OPENSSL_RAW_DATA);
    }
}
