openresty / openresty/lua-resty-string

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

Open
#61 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
443
Forks
143
Avg merge
2h 31m
Merged PRs (30d)
1

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting the repository's existing hex conversion and decrypt functions, then compare their expected input with the stored-value flow shown in the issue. Done should mean a documented API or decrypt behavior allows a hex-encoded encrypted value to be converted or decrypted consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
cryptography
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.