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

标签 c++ python encryption hash

我正在寻找允许我在我的应用和 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/

相关文章:

c++ - 如何打印数组中的第三大元素?

c++ - 为什么我的用于删除重复字符的 c++14 程序在输出中给出了额外的字符?

python - Pandas 将数据帧附加到另一个不合并列值的数据帧

python - Cython:在没有 NumPy 数组的情况下创建内存 View ?

php - Facebook即时游戏玩家签名验证失败

c++ - 用于在 vulkan 中渲染的辅助命令缓冲区

c++ - 使用 const 后缀自动解析成员函数

python - 如何通过 pip/pipenv CLI 获取更新包的变更日志?

amazon-web-services - Spark/Hadoop 不支持 AWS S3 上的 SSE-KMS 加密

密码函数在输出的最后一个字符中产生不需要的结果