crypt 模块未按预期输出 SHA512 哈希
crypt module not outputting a SHA512 hash as expected
我目前正在使用 Python 中的 crypt 模块尝试按以下方式创建 SHA512 哈希。
当我运行下面这行代码来自这个:
>>> import crypt
>>> crypt.crypt('password', '$' + 'salt1234')
而不是看到以下盐输出后跟每个 的 SHA512 散列:
'$salt1234$Zr07alHmuONZlfKILiGKKULQZaBG6Qmf5smHCNH35KnciTapZ7dItwaCv5SKZ1xH9ydG59SCgkdtsTqVWGhk81'
我得到以下信息:
FMi11BJFsAc
以下截图为证:
为什么我无法获得我期望的 SHA512 哈希值?
来自https://docs.python.org/3/library/crypt.html:
This module implements an interface to the crypt(3) routine, which is a one-way hash function based upon a modified DES algorithm; see the Unix man page for further details. […]
Notice that the behavior of this module depends on the actual implementation of the crypt(3) routine in the running system. Therefore, any extensions available on the current implementation will also be available on this module.
和from the documentation of the function itself(强调我的):
The optional salt is either a string as returned from mksalt()
, one of the crypt.METHOD_*
values (though not all may be available on all platforms)
您所在平台的 crypt
可能不支持 SHA-512。您可以通过检查 crypt.METHOD_SHA512
是否在 crypt.methods
.
中来确认这一点
>>> crypt.methods
[<crypt.METHOD_CRYPT>]
>>> "\N{CRYING FACE}"
''
可以看看 a description of SHAcrypt and make an implementation based on it, or use someone else’s。
from passlib.hash import sha512_crypt
sha512_crypt.hash('password')
我目前正在使用 Python 中的 crypt 模块尝试按以下方式创建 SHA512 哈希。
当我运行下面这行代码来自这个
>>> import crypt
>>> crypt.crypt('password', '$' + 'salt1234')
而不是看到以下盐输出后跟每个
'$salt1234$Zr07alHmuONZlfKILiGKKULQZaBG6Qmf5smHCNH35KnciTapZ7dItwaCv5SKZ1xH9ydG59SCgkdtsTqVWGhk81'
我得到以下信息:
FMi11BJFsAc
以下截图为证:
为什么我无法获得我期望的 SHA512 哈希值?
来自https://docs.python.org/3/library/crypt.html:
This module implements an interface to the crypt(3) routine, which is a one-way hash function based upon a modified DES algorithm; see the Unix man page for further details. […]
Notice that the behavior of this module depends on the actual implementation of the crypt(3) routine in the running system. Therefore, any extensions available on the current implementation will also be available on this module.
和from the documentation of the function itself(强调我的):
The optional salt is either a string as returned from
mksalt()
, one of thecrypt.METHOD_*
values (though not all may be available on all platforms)
您所在平台的 crypt
可能不支持 SHA-512。您可以通过检查 crypt.METHOD_SHA512
是否在 crypt.methods
.
>>> crypt.methods
[<crypt.METHOD_CRYPT>]
>>> "\N{CRYING FACE}"
''
可以看看 a description of SHAcrypt and make an implementation based on it, or use someone else’s。
from passlib.hash import sha512_crypt
sha512_crypt.hash('password')