<?php
// Encryption key and valid API key
$encryption_key = 'BondBdSecureKey1';  // must be exactly 16 chars for AES-128
$valid_api_key  = 'AbuTamim';

// Function to decrypt data coming from Android
function decryptData($text) {
    global $encryption_key;
    $decode = base64_decode($text);
    // AES-128-ECB with the same key as Android
    $decrypted = openssl_decrypt($decode, 'AES-128-ECB', $encryption_key, OPENSSL_RAW_DATA);
    return $decrypted;
}

// Validate API key (sent plain, not encrypted)
function validateApiKey($post_key) {
    if (!isset($post_key) || empty($post_key)) {
        return ['status' => false, 'message' => 'API key missing'];
    }

    global $valid_api_key;
    if ($post_key !== $valid_api_key) {
        return ['status' => false, 'message' => 'Invalid API key'];
    }

    return ['status' => true];
}
?>
