gpt4 book ai didi

Crypt 函数的 Python 用法

转载 作者:太空宇宙 更新时间:2023-11-04 02:57:43 34 4
gpt4 key购买 nike

如何在Python 3中实现crypt选项?

我理解的用途是:

Hash = crypt.crypt(password, salt)

但是,该函数有一组不同的散列函数。来自文档:

crypt.METHOD_SHA512 A Modular Crypt Format method with 16 character salt and 86 character hash. This is the strongest method.

crypt.METHOD_SHA256 Another Modular Crypt Format method with 16 character salt and 43 character hash.

crypt.METHOD_MD5 Another Modular Crypt Format method with 8 character salt and 22 character hash.

crypt.METHOD_CRYPT The traditional method with a 2 character salt and 13 characters of hash. This is the weakest method.

我的问题是如何选择函数使用的算法?

这是一个非常基本的问题,我不敢相信我自己找不到答案 - 如果我浪费了你的时间,我深表歉意。

最佳答案

您将方法作为盐参数传递。来自crypt function docstring :

If salt is not specified or is None, the strongest available method will be selected and a salt generated. Otherwise, salt may be one of the crypt.METHOD_* values, or a string as returned by crypt.mksalt().

例如:

crypt.crypt("password", crypt.METHOD_SHA512)

引擎盖下变成了:

crypt.crypt("password", crypt.mksalt(crypt.METHOD_SHA512))

关于Crypt 函数的 Python 用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41887491/

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