mirror of
https://github.com/opensim/opensim.git
synced 2026-05-14 02:39:52 +08:00
All is working fine :) The following script send a request to the PHP file where the encrypted string using osAESEncrypt() is decrypted and re-encrypted using the PHP openssl_XXXX. the return is the original string and the re-encrypted separated by "|"... the script decrypt the returned re-encrypted using osAESDecrypt() and log it in the chat. LSL script: <pre><code> // Change the url to point to your PHP file. string url = "http://127.0.0.1/aesTest.php"; string plainText = "Hello World :)"; string secret = "#!qUeRtY$@123^456€!#"; key r_id; default { touch_start(integer i) { string encryptedText = osAESEncrypt(secret, plainText); llOwnerSay("\nEncrypted with osAESEncrypt:\n"+ encryptedText); r_id = llHTTPRequest(url, [HTTP_METHOD,"POST",HTTP_MIMETYPE,"application/x-www-form-urlencoded",HTTP_BODY_MAXLENGTH,"16384"], "data="+ encryptedText); } http_response(key id, integer status, list metaData, string Response){ if(status = 200 ){ if(id == r_id){ if(Response != ""){ list temp = llParseString2List(Response,"|",[]); llOwnerSay("\nDecrypted using PHP openssl_decrypt:\n"+ llList2String(temp,0)); llOwnerSay("\nEncrypted using PHP openssl_encrypt:\n"+ llList2String(temp,1)); string decryptedText = osAESDecrypt(secret, llList2String(temp,1)); llOwnerSay("\nDecrypted with osAESDecrypt from PHP:\n"+ decryptedText); } else{ llOwnerSay("Enc/Dec Failed! Response:\n"+ Response); } } } else{ llOwnerSay("Destination not available.\nstatus: "+ status); } } } </code></pre> The PHP file: <pre><code> <?php if(getenv('REQUEST_METHOD') == 'POST') { $script_data = file_get_contents("php://input"); if($script_data){ $data = $_POST['data']; $secret = "#!qUeRtY$@123^456€!#"; $key = hex2bin(strtoupper(hash('sha256', $secret))); $iv = hex2bin(strtoupper(explode(":", $data)[0])); $encryptedText = hex2bin(strtoupper(explode(":", $data)[1])); $plainText = openssl_decrypt($encryptedText, "AES-256-CBC", $key, $options=OPENSSL_RAW_DATA, $iv); $retIv = openssl_random_pseudo_bytes(16); $reEncrypted = openssl_encrypt($plainText, "AES-256-CBC", $key, $options=OPENSSL_RAW_DATA, $retIv); echo $plainText && $reEncrypted ? $plainText."|".bin2hex($retIv).":".bin2hex($reEncrypted) : ""; } }; ?> </code></pre> Co-Authored-By: Ubit Umarov <469643+UbitUmarov@users.noreply.github.com>