Files
opensim/OpenSim/Framework
Adil El Farissi df8fe33007 Last cosmetics and PHP/LSL test scripts
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>
2024-02-29 01:09:20 +00:00
..
2022-12-15 22:19:09 +00:00
2023-11-12 22:24:53 +00:00
2022-03-13 02:05:56 +00:00
2022-10-16 19:21:54 +01:00
2023-06-23 01:21:04 +01:00
2022-04-17 22:13:33 +01:00
2020-05-17 17:16:29 +01:00
2022-01-08 23:35:56 +00:00
2023-03-10 09:09:00 +00:00
2022-01-09 02:28:51 +00:00
2017-08-29 07:38:52 +01:00
2022-10-05 01:53:24 +01:00
2022-01-08 23:35:56 +00:00
2023-05-21 20:46:54 +01:00
2022-01-13 20:31:52 +00:00
2021-07-16 03:08:31 +01:00
2019-10-22 11:55:27 +01:00
2022-04-23 16:41:18 +01:00
2022-01-13 13:59:41 +00:00
2020-08-28 23:41:34 +01:00
2023-04-25 23:53:26 +01:00
2020-08-22 12:38:35 +01:00
2023-02-25 12:40:37 +00:00
2022-09-20 21:32:10 +01:00
2022-01-08 23:35:56 +00:00
2024-01-02 23:07:12 +00:00
2022-10-16 15:06:36 +01:00
2023-11-29 12:17:08 +00:00
2022-11-12 03:27:11 +00:00
2022-03-13 02:05:56 +00:00
2021-07-23 03:04:59 +01:00
2023-02-24 12:35:12 +00:00
2023-02-23 23:56:46 +00:00
2022-10-16 15:06:36 +01:00
2023-05-13 16:39:14 +01:00
2023-03-29 20:11:04 +01:00