I am implementing aadhar card api and I got stuck in generating PID and sKey xml block for input xml data, following is the requirement for both key element.
PID block data should be encrypted with a dynamic session key using AES-256 symmetric algorithm (AES/ECB/PKCS7Padding). Session key, in turn, is encrypted with 2048-bit UIDAI public key using asymmetric algorithm (RSA/ECB/PKCS1Padding).
Skey Value of this element is base-64 encoded value of encrypted 256-bit AES session key.
Below is the code what I have created:
/////////////////////
$ci = '20170922';
$method = 'AES-256-ECB';
$skey = openssl_encrypt (session_id(), $method ,$ci, true);
$pid_block = '<Pid ts="2016061512000000" ver="1.0"><Demo lang=""><Pi ms="E" mv="" name="Shivshankar Choudhury" lname="" lmv="" gender="" dob="" dobt="" age="" phone="" email="" /></Demo></Pid>';
$pid_encoded = base64_encode($pid_block);
$hash_256_pid = hash ( 'sha256' , $pid_block);
$hmac_pid_block = openssl_encrypt($hash_256_pid , $method , session_id());
$encoded_hmac_pid_block = base64_encode($hmac_pid_block);
$xml_data = '<Auth ac="public" sa="public" ver="1.6" txn="706bf70d" tid="public" uid="999999990019"><Uses pi="y" pa="n" pfa="n" bio="y" bt="FMR" otp="n" pin="n"/><Meta udc="UIDAI:SampleClient" fdc="NC" idc="NA" pip="127.0.0.1" lot="P" lov="560103"/><Skey ci="20131003" >'.$skey.'</Skey><Data type="X">'.$pid_encoded.'</Data><Hmac>'.$encoded_hmac_pid_block.'</Hmac></Auth>';
echo $xml_data;
$url = "http://auth.uidai.gov.in/1.6/public/9/9/";
//setting the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// Following line is compulsary to add as it is:
curl_setopt($ch, CURLOPT_POSTFIELDS,
"xmlRequest=" . $xml_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
$data = curl_exec($ch);
curl_close($ch);
//convert the XML result into array
$array_data = json_decode(json_encode(simplexml_load_string($data)), true);