简体   繁体   English

crypt 模块未按预期输出 SHA512 hash

[英]crypt module not outputting a SHA512 hash as expected

I'm currently using the crypt module in Python to try and create a SHA512 hash in the following manner.我目前正在使用 Python 中的 crypt 模块尝试以下列方式创建 SHA512 hash。

When I run the following line of code from this SO post :当我从这个SO 帖子运行以下代码行时:

>>> import crypt
>>> crypt.crypt('password', '$6$' + 'salt1234')

Instead of seeing the following output of the salt followed by the SHA512 hash per this SO post :而不是看到以下盐的 output 后跟 SHA512 hash 每这个 SO 帖子

'$6$salt1234$Zr07alHmuONZlfKILiGKKULQZaBG6Qmf5smHCNH35KnciTapZ7dItwaCv5SKZ1xH9ydG59SCgkdtsTqVWGhk81'

I get the following:我得到以下信息:

$6FMi11BJFsAc

Below is a screenshot as proof:下面是截图为证:

在此处输入图像描述

Why is it that I'm unable to obtain the SHA512 hash that I'm expecting?为什么我无法获得我期待的 SHA512 hash?

From https://docs.python.org/3/library/crypt.html :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;该模块实现了crypt(3)例程的接口,该例程是基于改进的 DES 算法的单向 hash function; see the Unix man page for further details.有关详细信息,请参阅 Unix 手册页。 […] […]

Notice that the behavior of this module depends on the actual implementation of the crypt(3) routine in the running system.请注意,此模块的行为取决于运行系统中crypt(3)例程的实际实现。 Therefore, any extensions available on the current implementation will also be available on this module.因此,当前实现中可用的任何扩展也将在此模块上可用。

and from the documentation of the function itself (emphasis mine):从 function 本身的文档(强调我的):

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 )可选的 salt 是从mksalt()返回的字符串,是crypt.METHOD_*值之一(尽管并非所有平台都可用

The crypt of the platform you're on probably doesn't support SHA-512.您所在平台的crypt可能不支持 SHA-512。 You can confirm this by checking whether crypt.METHOD_SHA512 is in crypt.methods .您可以通过检查crypt.METHOD_SHA512是否在crypt.methods中来确认这一点。

>>> crypt.methods
[<crypt.METHOD_CRYPT>]
>>> "\N{CRYING FACE}"
'😢'

One could look at a description of SHAcrypt and make an implementation based on it, or use someone else's .可以查看SHAcrypt 的描述并基于它进行实现,或者使用其他人的.

from passlib.hash import sha512_crypt
sha512_crypt.hash('password')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM