-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Description
Missing feature
crypto.fromHex
The missing counterpart to crypto.toHex
Provides an ASCII char representation of a (hex) Lua string. Each hex byte in the input string is represented as two hex characters.
For example: "48656c6c6f576f726c64"
Justification
The use of encrypt and decrypt is for purposes where the original value is required at a later date. Using toHex is very useful, but when this is later required, the hex data string must be converted back into the original char string.
Workarounds
Currently using this code:
--First encrypt the data
local output = crypto.toHex(crypto.encrypt("AES-ECB","mykey","data"))
--Then decrypt the data WITHOUT the use of 'crypto.fromHex'
local input
for i=1, #output, 2 do
if not input then
input=string.char("0x"..string.sub(output,i,i+1))
else
input=input..string.char("0x"..string.sub(output,i,i+1))
end
end
return crypto.decrypt("AES-ECB", "mykey", input):match("(.-)%z*$")
--Or decrypt the data WITH the use of 'crypto.fromHex'
local input = crypto.fromHex(output)
return crypto.decrypt("AES-ECB", "mykey", input):match("(.-)%z*$")
Metadata
Metadata
Assignees
Labels
No labels