将纯文本密码转换为 MD5 salted hash

发布于 2024-12-20 09:22:49 字数 383 浏览 3 评论 0原文

例如,在 FreeBSD 下,密码存储在 /etc/master.passwd 中,如下所示:

$1$7wtGfwgp$772bEQInetnJKUNtLM0Xt/

我使用的密码是“Test11”。据我了解,$1$ 意味着它是哈希 MD5 密码?如果知道盐和密码并使用 md5sum,如何得出最终的哈希值“772bEQInetnJKUNtLM0Xt/”?据我了解,它应该是这样的:

$ echo -n $(echo -n 7wtGfwgp)$(echo -n Test11) | md5sum

..但这不太匹配。我做错了什么?

PS 我问这个问题是为了了解类 UNIX 操作系统下的密码哈希系统。

For example under FreeBSD passwords are stored in /etc/master.passwd like this:

$1$7wtGfwgp$772bEQInetnJKUNtLM0Xt/

The password I used was "Test11". As I understand, $1$ means that it's a hashed MD5 crypt? How can one come up with the final hash "772bEQInetnJKUNtLM0Xt/" if he is aware of salt and password and uses md5sum? As I understand, it should be something like:

$ echo -n $(echo -n 7wtGfwgp)$(echo -n Test11) | md5sum

..but this doesn't quite match up. What am I doing wrong?

PS I'm asking this in order to understand the password hashing system under UNIX-like operating systems.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉城已无爱 2024-12-27 09:22:49

我使用的是 Linux,我不确定 FreeBSD 是否实际上使用相同的算法,但是您可以查看这些信息来源(希望 FreeBSD 上也是如此):

基于最后一页,此 PHP 脚本将生成您期望的输出(给定您的密码和盐):

<?php
$password = 'Test11';
$salt = '$1$7wtGfwgp

您可以使用例如 Python 执行相同的操作:

import crypt

password = 'Test11'
salt = '$1$7wtGfwgp

基于此 Python 文档页面:

基于维基百科文章:

你可以看到crypt 函数的来源,例如:

作为旁注,这是一个很好的在线哈希生成器:

希望这会有所帮助。

; echo 'Crypt hash: ' . crypt($password, $salt) . "\n" ?>

您可以使用例如 Python 执行相同的操作:


基于此 Python 文档页面:

基于维基百科文章:

你可以看到crypt 函数的来源,例如:

作为旁注,这是一个很好的在线哈希生成器:

希望这会有所帮助。

print(crypt.crypt(password, salt))

基于此 Python 文档页面:

基于维基百科文章:

你可以看到crypt 函数的来源,例如:

作为旁注,这是一个很好的在线哈希生成器:

希望这会有所帮助。

; echo 'Crypt hash: ' . crypt($password, $salt) . "\n" ?>

您可以使用例如 Python 执行相同的操作:

基于此 Python 文档页面:

基于维基百科文章:

你可以看到crypt 函数的来源,例如:

作为旁注,这是一个很好的在线哈希生成器:

希望这会有所帮助。

I'm on Linux and I am not sure whether FreeBSD actually uses the same algorithm, but you can take a look at these sources of information (hope the same is on FreeBSD):

Based on the last page, this PHP script will produce the output you expect (given your password and salt):

<?php
$password = 'Test11';
$salt = '$1$7wtGfwgp

You can do the same using e.g. Python:

import crypt

password = 'Test11'
salt = '$1$7wtGfwgp

based on this Python doc page:

Based on the Wikipedia article:

you can see the source of crypt function e.g. here:

As a side note, here's a nice online hash generator:

Hope this helps.

; echo 'Crypt hash: ' . crypt($password, $salt) . "\n" ?>

You can do the same using e.g. Python:


based on this Python doc page:

Based on the Wikipedia article:

you can see the source of crypt function e.g. here:

As a side note, here's a nice online hash generator:

Hope this helps.

print(crypt.crypt(password, salt))

based on this Python doc page:

Based on the Wikipedia article:

you can see the source of crypt function e.g. here:

As a side note, here's a nice online hash generator:

Hope this helps.

; echo 'Crypt hash: ' . crypt($password, $salt) . "\n" ?>

You can do the same using e.g. Python:

based on this Python doc page:

Based on the Wikipedia article:

you can see the source of crypt function e.g. here:

As a side note, here's a nice online hash generator:

Hope this helps.

吖咩 2024-12-27 09:22:49

散列和加密是不同的,即使散列是加密的一部分;)

所以如果你想加密它,请像 icyrock 发布的那样进行。 md5sum(freebsd coreutils 中的gmd5sum)仅创建有关某些输入的哈希和 (RFC 1321)。它不会像(几个)加密代码那样使用此哈希在进一步的步骤中进行加密。

这就是为什么您的代码会给出完全不同的结果。

Hashing and crypting is something different, even if hashing is a part of crypting ;)

So if you want to crypt it, do it like icyrock posted. md5sum (gmd5sum in freebsd coreutils) does only create a hash sum (RFC 1321) about some input. It's not using this hash to crypt in a further step as (several) crypt codes does.

That's why your code gives you something completely different as result.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文