File: /var/www/vhost/disk-apps/demo.sports-crowd.com/app/Http/Controllers/CityPrimeController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class CityPrimeController extends Controller
{
private $method = "AES-256-CBC";
private $key;
private $iv;
// Genera un token en base al JSON User Information.
// Structure:
// {
// first_name: 'Santiago', #required
// last_name: 'Barcenas', #optional
// email: 'jsbarcenas@gmail.com', #required
// phone: 3003140000, #required
// }
function createToken(Request $request){
$userInformation = $request->getContent();
$this->key = config("city_prime.city_prime_key");
$this->iv = config("city_prime.city_prime_iv");
return $this->encrypt($userInformation);
}
function strtohex($x)
{
$s='';
foreach (str_split($x) as $c) $s.=sprintf("%02X",ord($c));
return($s);
}
function encrypt($plaintext) {
$keyHex = hex2bin($this->key);
$ivHex = hex2bin($this->iv);
$ciphertext = openssl_encrypt($plaintext, $this->method, $keyHex, OPENSSL_RAW_DATA, $ivHex);
$data = array('status' => 'success', 'token' => $this->strtohex($ciphertext));
return response()->json($data, 200);
}
}