How can I retrieve a password such that it can securely be deleted from memory later?

孤者浪人 提交于 2019-12-11 06:44:54

问题


How can I retrieve a password from user input in Lua in a way that it can securely be deleted from memory after the program is done using the password?

This is a followup to: lua aes encryption

How can I convert a password to hexadecimals in lua?

A simple example would be:

"pass" becomes {0x70,0x61,0x73,0x73}


回答1:


What do you mean by "hexadecimals"? Do you want to convert pass to a string containing #pass*2 hexadecimal characters? Then you want this:

function toHex(s)
    return (string.gsub(s, ".", function (c)
        return string.format("%02X", string.byte(c))
      end))
end
print(toHex('password')) --> 70617373776F7264

Or do you want a table of numbers, where each number is one character code (byte)? Then you want this:

function toBytes(s)
    return {string.byte(s, 1, #s)}
end
print(table.concat(toBytes('password'), ',')) --> 112,97,115,115,119,111,114,100


来源:https://stackoverflow.com/questions/9056323/how-can-i-retrieve-a-password-such-that-it-can-securely-be-deleted-from-memory-l

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!