Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function missing to convert stored hex value back to Ascii for decrypt function #61

Open
doktoroblivion opened this issue Jul 10, 2018 · 1 comment

Comments

@doktoroblivion
Copy link

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.

@doktoroblivion 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
@rocky1001
Copy link

same problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants