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

You need to generate the string and pass it into this function. It requires lua-resty-string package.
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

function encrypt(plaintext)
	local aes = require "resty.aes"

	local key = "YourKeyGoesHere"
	local _aes = aes:new(key)
	local bin = _aes:encrypt(plaintext)
	local hex = tohex(bin)

	return hex
end

function tohex(str)
    return (str:gsub('.', function (c)
        return string.format('%02X', string.byte(c))
    end))
end

 

Leave a Reply

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