如何检索密码,以便以后可以安全地从内存中删除? [英] How can I retrieve a password such that it can securely be deleted from memory later?

查看:181
本文介绍了如何检索密码,以便以后可以安全地从内存中删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从Lua的用户输入中检索密码,方法是使用密码在程序完成后可以从内存中安全地删除密码?

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?

是追踪: lua aes加密

如何在lua中将密码转换为十六进制?

How can I convert a password to hexadecimals in lua?

一个简单的例子是:


pass成为{0x70,0x61,0x73,0x73}

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


推荐答案

十六进制是什么意思?要将 pass 转换为包含#pass * 2 十六进制字符的字符串?那么你想要这样:

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

这篇关于如何检索密码,以便以后可以安全地从内存中删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆