This snippet of PHP code will encrypt the variables and values string into the required format.

You will need to generate the string and pass it into this function.
Example, pass it the string:

variable1=value1;variable2=value2;variable3=value3

It will return:

9af21fffc0fa29f990913ce8f56160e354991f71d25d20ef0d4990b42d72607e111bf936012ae2cf30e3c5fd974c3f7b6ba07db6eb07498571ea8473c81d3945

Then put this in the CDN URL:

http://cdn.yoursite.com/9af21fffc0fa29f990913ce8f56160e354991f71d25d20ef0d4990b42d72607e111bf936012ae2cf30e3c5fd974c3f7b6ba07db6eb07498571ea8473c81d3945/file.ext

Or for Real Time Zone

rtmp|rtsp://cdn.yoursite.com/live/zone_stream_9af21fffc0fa29f990913ce8f56160e354991f71d25d20ef0d4990b42d72607e111bf936012ae2cf30e3c5fd974c3f7b6ba07db6eb07498571ea8473c81d3945

The Code

PHP version >= 5.3.0

PHP versions 5.3.0 and above can use the openssl_encrypt method

function encrypt($plaintext)
{
	$key = 'YourKeyGoesHere';

	// generate key and iv
	$keyMD5 = md5($key, true);
	$initializationVector = md5($keyMD5 . $key, true);

	// select encryption method
	$encryptionMethod = openssl_get_cipher_methods()[0]; #AES-128-CBC

	// encrypt & hex encode
	$binary = openssl_encrypt($plaintext, $encryptionMethod, $keyMD5, $rawOutput = true, $initializationVector);
	$hex = bin2hex($binary);

	return $hex;
}

PHP version < 5.3.0

PHP versions prior to 5.3.0 must use the php5-mcrypt extension.  This extension has been deprecated as of PHP 7.1.0 and moved to PECL as of PHP 7.2.0.

function encrypt($plaintext)
{
    $key = "YourKeyGoesHere";

    // generate key and iv
    $key_md5 = md5($key, true);
    $iv_md5 = md5("$key_md5$key", true);

    // fix padding for openssl compatability
    $mod = strlen($plaintext) % 16;
    $numpad = 16 - $mod;
    $pad = pack("c", $numpad);
    $padded = $plaintext;
    for ($i = 0; $i < $numpad; $i++)
    {
        $padded = $padded.$pad;
    }

    // finally encrypt & hex encode
    $crypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key_md5, $padded, MCRYPT_MODE_CBC, $iv_md5);
    $hex = bin2hex($crypt);

    return $hex;
}

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *