(更新)
在 Lua 代码中,物理访问没有安全性。除了其他答案:ESP 可以选择保存 wifi 设置。因此,这将允许您不将凭据放入 lua 文件中。对凭据进行一次编程,然后删除凭据代码。这将使获取凭据变得更加困难。至少阅读代码的人不会看到它。(但当然不是一个完整的安全选项,因为这个。)每次 esp 重新启动或 wifi 网络在范围内时,它都会连接到相同的 ssid 和网络。这是默认开启的。
wifi.setmode(wifi.STATION)
wifi.sta.config("SSID", "password")
wifi.sta.connect()
另一种方法是mac地址注册。如果您的 AP 允许您注册站点的 mac 地址,那么它将提供多一层安全性,因为获取密码不足以连接 wifi 网络。这不是保护您的密码!您需要配置您的 AP 来执行此操作。
另一种方法:这将需要更多代码。我不能说它更安全,但它会让它更难被发现。你应该编译你的 lua 文件来使用它。只需使用 ssid 异或您的密码,然后将异或后的版本放入您的代码中。调查网络并为每个网络创建密码。尝试将每个人与制作的通行证联系起来。匹配对将成功连接。其他人将失败。这将使连接序列更长一点。
--encode
--retuns a table containing bytes
--also prints what should be in code
-- s is ssid, p is password
function encode(s,p)
key = s..s --encoding key, must be longer than password
enc = {} --new table
uart.write(0,"Key output: {")
for i=1,string.len(p) do
c = bit.bxor(p:byte(i),key:byte(i))
table.insert(enc,c)
if i == string.len(p) then
uart.write(0,c.."}")
else
uart.write(0,c..",")
end
end
return enc
end
--decode
--tries to decode password with table enc
--s is ssid (got from survey) encval is byte table
function decode(s,encval)
key=s..s
pass=""
for ii,i in ipairs(encval) do
c = bit.bxor( key:byte(ii),i)
pass = pass..string.char(c)
end
print("password: "..pass)
return pass
end
-- lets say ssid="network" and password="psswrd12"
encodedpass = encode("network","psswrd12")
-- this will print: Key output: {30,22,7,0,29,22,90,92}
-- this will be included in code
-- and to decode
print(decode("network",encodedpass))
-- will print: password: psswrd12