gpt4 book ai didi

c++ - 改进我的共享 secret 算法/方法并建议加密协议(protocol)

转载 作者:太空狗 更新时间:2023-10-29 21:28:22 26 4
gpt4 key购买 nike

我正在寻找允许我在我的应用和 HTML 页面之间使用共享 secret 的协议(protocol)/算法。

共享 secret 旨在确保只有拥有该应用程序的人才能访问该网页。

我的问题:我不知道应该使用什么算法(我验证对 HTML 页面的有效访问的方法)以及我应该使用什么加密协议(protocol)。

人们向我建议我使用 HMAC SHAXXX 或 DES 或 AES,我不确定我应该使用哪个 - 你有什么建议吗?

我的算法是这样的:

  • I create a shared secret that the App & the HTML page know of(lets call it "MySecret"). To ensure that that shared secret is always unique I will add the current date & minute to the end of the secret then hash it using XXX algorithm/protocol(HMAC/AES/DES). So the unencrypted secret will be "MySecret08/17/2011-11-11" & lets say the hash of that is "xyz"
  • I then add this hash to the url CGI: http://mysite.com/comp.py?sharedSecret=xyz
  • The comp.py script then uses the same shared secret & date combination, hashes it, then checks that the resulting hash is the same as the CGI variable sharedSecret("xyz"). If it is then I know a valid user is accessing the webpage.

你能想出更好的方法来确保有效的人可以访问我的网页(该网页允许用户参加比赛)吗?

我认为我在使用共享 secret 的正确轨道上,但我验证 secret 的方法似乎有缺陷,特别是如果哈希算法不会为相同的输入产生相同的结果时间。

最佳答案

especially if the hash algorithm doesn't produce the same result for the same in put all the time.

然后散列被破坏。为什么不呢?

在简单的情况下,您需要 HMAC。您正在使用共享 key “签署”您的请求,并且签名由服务器验证。请注意,HMAC 应包含更多数据以防止重播攻击——实际上它应包含所有查询参数(按指定顺序)以及序列号以防止窃听者重播同一消息。如果您要验证的只是共享 key ,则任何无意中听到该消息的人都可以继续使用此共享 key ,直到它过期为止。通过包含序列号或较短的有效期,您可以将服务器配置为对其进行标记。

请注意,这仍然不完美。 TLS 支持客户端和服务器端证书支持 - 为什么不使用它?

关于c++ - 改进我的共享 secret 算法/方法并建议加密协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7087395/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com