python - 用于安全的目的是什么?

标签 python python-3.x security hash

Python 3.9 中 hashlib 中的每个哈希函数都添加了参数 usedforsecurity

Changed in version 3.9: All hashlib constructors take a keyword-only argument usedforsecurity with default value True. A false value allows the use of insecure and blocked hashing algorithms in restricted environments. False indicates that the hashing algorithm is not used in a security context, e.g. as a non-cryptographic one-way compression function.

但是,这提供了指导

  1. 什么时候应该使用usedforsecurity
  2. 什么时候你不应该使用usedforsecurity
  3. 什么是“受限环境”

虽然我不是安全研究人员,但我非常清楚 md5 在任何意义上都安全。因此,usedforsecurity 这个名字在很多方面都让我感到困惑。

usedforsecurity 的意义何在?

最佳答案

文档中给出的解释非常清楚何时应该或不应该使用 usedforsecurity:如果您不出于安全目的使用该算法,则传递 False .

其效果确实值得更多解释。在大多数 Python 版本中,此参数不执行任何操作。默认情况下启用不安全算法。

“受限环境”主要是使用OpenSSL FIPS module的Python的罕见构建。 (或 3.0 之前的 OpenSSL 上的 OpenSSL FIPS 模式)以禁用不安全的算法。如果您传递 usedforsecurity=False,Python 将告诉 OpenSSL 无论如何都允许不安全的算法(如果您想查看代码,请参阅 hereherehere )。如果您确实不将该算法用于任何需要加密强度保证的事情,那么这是可以的。

如果您想了解更多信息,还可以查看issue discussion这最初导致引入此标志。

关于python - 用于安全的目的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77425682/

相关文章:

python - BeautifulSoup : Get the Contents of Sub-Nodes

python - 使用 Tesseract OCR 从表格图像中识别特定数字

python - 为什么 Zappa 部署缺少虚拟环境中存在的所有/大多数包?

python - Python中的函数语句返回列表列表中某些列表的总和

python - 用于对称运算的 spark 笛卡尔上三角 : `x*(x+1)//2` instead of `x**2`

python - 使用 Python 删除 IP 地址中的前导零

python - 修改 tk.Button 上的部分文本

WCF传输安全弱点

iphone - 在 iOS 上使用 CFStream 套接字接受不受信任的 SSL 服务器证书

security - CSRF 不是浏览器安全问题吗?