<?php
error_reporting(E_ERROR | E_PARSE);
//include Firebase/JWT/JWT;

require '../Firebase/JWT/JWT.php';

$key = "-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArxd93uLDs8HTPqcSPpxZrf0
Dc29r3iPp0a8filjAyeX4RAH6lWm9qFt26CcE8ESYtmo1sVtswvs7VH4Bjg/FDlRpd+MnAlX
uxChij8/vjyAwE71ucMrmZhxM8rOSfPML8fniZ8trr3I4R2o4xWh6no/xTUtZ02/yUEXbphw3
DEuefzHEQnEF+quGji9pvGnPO6Krmnri9H4WPY0ysPQQQd82bUZCk9XdhSZcW/am8w
BulYokITRMVHlbRXqu1pOFmQMO5oSpyZU3pXbsx+OxIOc4EDX0WMa9aH4+snt18WA
XVGwF2B4fmBk7AtmkFzrTmbpmyVqA3KO2IjzMZPw0hQIDAQAB
-----END PUBLIC KEY-----";


if (isset($_REQUEST['data'])){
    if (trim($_REQUEST['data']) != ''){
        $encrypted = $_REQUEST['data'];
        $decoded = JWT::decode($encrypted, $key, array('RS256'));

        echo $jsonformat = json_encode($decoded);
        //return $decoded;
        exit;

        // $Result = decrypt($encrypted);
        // echo $Result;
        // exit;
    }
}

function decrypt($data)
    {
        $key = "-----BEGIN PUBLIC KEY-----
        MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArxd93uLDs8HTPqcSPpxZrf0
        Dc29r3iPp0a8filjAyeX4RAH6lWm9qFt26CcE8ESYtmo1sVtswvs7VH4Bjg/FDlRpd+MnAlX
        uxChij8/vjyAwE71ucMrmZhxM8rOSfPML8fniZ8trr3I4R2o4xWh6no/xTUtZ02/yUEXbphw3
        DEuefzHEQnEF+quGji9pvGnPO6Krmnri9H4WPY0ysPQQQd82bUZCk9XdhSZcW/am8w
        BulYokITRMVHlbRXqu1pOFmQMO5oSpyZU3pXbsx+OxIOc4EDX0WMa9aH4+snt18WA
        XVGwF2B4fmBk7AtmkFzrTmbpmyVqA3KO2IjzMZPw0hQIDAQAB
        -----END PUBLIC KEY-----";

        if (openssl_private_decrypt($data, $decrypted, $key)) //base64_decode
            $data = $decrypted;
        else
            $data = 'Not Done...';

        return $data;
    }
?>