You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The functions you have are very good, but they make the assumption that if you want to encrypt and decrypt you will always have the encrypted ascii value (non-converted around). If you have to store this value into a cache table or dictionary there is no existing function (aside from atoi) to convert it back to something the decrypt function will take. So, there are two options:
provide a new function to convert any stored value back to ascii
change the decrypt function to handle hex and other data primitives
The code that I have had to use to invoke decrypt from a stored value. cache_key is supplied by an OS envvar.
local cache_key = os.getenv("ENCRYPT_KEY");
-- hex to char conversion, used to perform substitution
local c_table = {};
for jj = 0, 255 do
c_table[("%02X"):format(jj)] = string.char(jj);
c_table[("%02x"):format(jj)] = string.char(jj);
end
-- decryptIt function
local function decryptIt(value)
local aes_128_cbc_md5 = aes:new(cache_key);
return aes_128_cbc_md5:decrypt(value);
end
-- convert to ascii
local function convertAscii(value)
return value:gsub("(..)", c_table);
end
local value = encryptIt(init_value);
.
.
ngx.header['Set-Cookie'] = { "hash_val=" .. str.to_hex(value) .. }
.
. ( a lot of code and reinvoke of proxy, etc... )
.
local url = ngx.var['cookie_hash_val'];
local d_crypted = decryptIt(convertAscii(url));
I think I have the above correct, but if you have any questions let me know.
The text was updated successfully, but these errors were encountered:
doktoroblivion
changed the title
Function missing to convert store hex value back to Ascii for decrypt function
Function missing to convert stored hex value back to Ascii for decrypt function
Jul 11, 2018
The functions you have are very good, but they make the assumption that if you want to encrypt and decrypt you will always have the encrypted ascii value (non-converted around). If you have to store this value into a cache table or dictionary there is no existing function (aside from atoi) to convert it back to something the decrypt function will take. So, there are two options:
The code that I have had to use to invoke decrypt from a stored value.
cache_key
is supplied by an OS envvar.I think I have the above correct, but if you have any questions let me know.
The text was updated successfully, but these errors were encountered: