In localhost i'm trying to develope and test my REST API. I have this code that send a JSON encrypted to the REST API
//The url i wish to send the POST request to
$url = "http://localhost/api/2.php";
$headers = array(
"Accept: application/json",
"Content-Type: application/json",
);
// Key
$encryption_key = "43274689933404c4bd47190b395f5e3a2c668fcca603c40ceb074c970047402d";
$iv = "274f5f54eff39aee1e4d2c614ccd99c9";
$method = "AES-256-CBC";
//The data to send via POST
$data = [
'username' => "RERERE",
'password' => "bbbb"
];
// Encrypted data
$encrypted = base64_encode(openssl_encrypt($data, $method, $encryption_key, 0, $iv));
//open connection
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch,CURLOPT_POSTFIELDS, $encrypted);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
//execute post
$result = curl_exec($ch);
echo $result;
Now in 2.php file i can't retreive the content, i'm using something like this below but i got NULL
// Key
$encryption_key = "43274689933404c4bd47190b395f5e3a2c668fcca603c40ceb074c970047402d";
$iv = "274f5f54eff39aee1e4d2c614ccd99c9";
$method = "AES-256-CBC";
$json = file_get_contents('php://input',true);
$array = json_decode($json);
$decrypted = openssl_decrypt(base64_decode($array), $method, $encryption_key, 0, $iv);
echo $decrypted;
Can someone help me to unsderstand what is wrong and if this is the right way to do this?