BigBrother Posted September 7, 2013 Posted September 7, 2013 Hello guys, I'd like to know if LUA supports the MD5 + salt 's encryption method ? Or if it doesn't, which method of encryption could I use ? Thanks.
TAPL Posted September 7, 2013 Posted September 7, 2013 https://wiki.multitheftauto.com/wiki/Md5 https://wiki.multitheftauto.com/wiki/Sha256
ixjf Posted September 7, 2013 Posted September 7, 2013 I wrote a function which hashes a string and automatically creates a random key (salt) for you. It's pretty simple, and you can also provide your own salt generator function to use instead of the built-in one: function md5_salt(str, static_salt, salt_func) assert(str, "You need to pass a string to hash as first argument!") local salt__new = salt_func if not salt__new then salt__new = function() math.randomseed(getTickCount()) local salt = {} for i = 1, 80 do salt[i] = string.char(math.random(126)) end return table.concat(salt, "") end end if not static_salt or static_salt:len() == 0 then outputDebugString("md5_salt: It is recommended that you use a static salt.") static_salt = "" end local salt = salt__new() return md5(("%s%s%s"):format(str, static_salt, salt)), salt end Example (using static salt with built-in salt generator): local hash, salt = md5_salt("I'm an awesome string.", "in| {}D(p?ok+9UzVi:_'UTG{[s")outputChatBox("Hash: " .. hash)outputChatBox("Salt: " .. salt) Another example (using static salt with a different salt generator function): local function salt__new() math.randomseed(getTickCount()) local salt = {} for i = 1, 20 do salt[i] = string.char(math.random(63) * 2) end return table.concat(salt, "")end local hash, salt = md5_salt("I'm an awesome string.", "in| {}D(p?ok+9UzVi:_'UTG{[s", salt__new)outputChatBox("Hash: " .. hash)outputChatBox("Salt: " .. salt) I used to know how to code, but then I took an arrow in the knee. Project Redivivus - Remaking Old School MTA With New Code MTA 0.6 Nightly 1 released
MTA Team qaisjp Posted September 7, 2013 MTA Team Posted September 7, 2013 improved ixjf's code function md5_salt(str, static_salt, salt_func) assert(str, "You need to pass a string to hash as first argument!") local salt__new = salt_func or function() math.randomseed(getTickCount()) local salt = {} for i = 1, 80 do salt[i] = string.char(math.random(126)) end return table.concat(salt, "") end end if not static_salt or static_salt:len() == 0 then outputDebugString("md5_salt: It is recommended that you use a salt.") static_salt = "" end local salt = salt__new() return md5(("%s%s%s"):format(str, static_salt, salt)), salt end
ixjf Posted September 7, 2013 Posted September 7, 2013 In fact, there's no real difference whatsoever, it is just my coding style. I used to know how to code, but then I took an arrow in the knee. Project Redivivus - Remaking Old School MTA With New Code MTA 0.6 Nightly 1 released
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now