什么 PHP 函数生成 sha-1 128 位密钥?

发布于 2024-11-28 12:34:20 字数 63 浏览 0 评论 0原文

使用sha1()函数,它生成40个字符的密钥,即160位。但我正在寻找一个生成 sha-1 128 密钥的函数?

Using sha1() function, it generates 40 character key which is 160 bit. But I am looking for a function that generates sha-1 128 key?

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

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

发布评论

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

评论(2

洒一地阳光 2024-12-05 12:34:20

不存在 128 位 SHA-1 这样的东西。 顺便说一句, SHA-1 是 160 位

SHA-1 有明显的弱点。

这可能会令人感兴趣:

<?php 
$data = "hello"; 

foreach (hash_algos() as $v) { 
        $r = hash($v, $data, false); 
        printf("%-12s %3d %s\n", $v, strlen($r), $r); 
} 
?> 

来自此处(用户贡献的评论)。

There is no such thing as a 128bit SHA-1. SHA-1 is 160 bits

BTW, SHA-1 has significant weaknesses.

This may be of interest:

<?php 
$data = "hello"; 

foreach (hash_algos() as $v) { 
        $r = hash($v, $data, false); 
        printf("%-12s %3d %s\n", $v, strlen($r), $r); 
} 
?> 

From here (user contributed comments).

贵在坚持 2024-12-05 12:34:20

以下哈希算法应呈现 128 位摘要:

hash("md2", $text);
hash("md4", $text);
hash("md5", $text);
hash("ripemd128", $text);
hash("tiger128,3", $text);
hash("tiger128,4", $text);
hash("haval128,3", $text);
hash("haval128,4", $text);
hash("haval128,5", $text);

这些算法呈现 32 个十六进制字符,每个字符 1 个半字节(4 位):

          = 1/2417851639229258349412352 yottabyte
          = 1/2361183241434822606848 zettabyte
          = 1/2305843009213693952 exabyte
          = 1/2251799813685248 petabyte
          = 1/2199023255552 terabyte
          = 1/2147483648 gigabyte
          = 1/2097152 megabyte
          = 4/1048576 Megabit
          = 1/2048 kilobyte
          = 4/1024 Kilobit
          = 1/2 byte
   nibble = 1 nibble
          = 4 bits

32 X 4 = 128 位

算法输出示例:

<?php 
$data = "hello"; 

foreach (hash_algos() as $v) { 
        $r = hash($v, $data, false); 
        printf("%-12s %3d %s\n", $v, strlen($r), $r); 
} 
?> 

which produce (long hashes are cropped) 

md2           32 a9046c73e00331af68917d3804f70655                   
md4           32 866437cb7a794bce2b727acc0362ee27 
md5           32 5d41402abc4b2a76b9719d911017c592 
sha1          40 aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d 
sha256        64 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e730 
sha384        96 59e1748777448c69de6b800d7a33bbfb9ff1b463e44354c3553 
sha512       128 9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2d 
ripemd128     32 789d569f08ed7055e94b4289a4195012 
ripemd160     40 108f07b8382412612c048d07d13f814118445acd 
ripemd256     64 cc1d2594aece0a064b7aed75a57283d9490fd5705ed3d66bf9a 
ripemd320     80 eb0cf45114c56a8421fbcb33430fa22e0cd607560a88bbe14ce 
whirlpool    128 0a25f55d7308eca6b9567a7ed3bd1b46327f0f1ffdc804dd8bb 
tiger128,3    32 a78862336f7ffd2c8a3874f89b1b74f2 
tiger160,3    40 a78862336f7ffd2c8a3874f89b1b74f2f27bdbca 
tiger192,3    48 a78862336f7ffd2c8a3874f89b1b74f2f27bdbca39660254 
tiger128,4    32 1c2a939f230ee5e828f5d0eae5947135 
tiger160,4    40 1c2a939f230ee5e828f5d0eae5947135741cd0ae 
tiger192,4    48 1c2a939f230ee5e828f5d0eae5947135741cd0aefeeb2adc 
snefru        64 7c5f22b1a92d9470efea37ec6ed00b2357a4ce3c41aa6e28e3b 
gost          64 a7eb5d08ddf2363f1ea0317a803fcef81d33863c8b2f9f6d7d1 
adler32        8 062c0215 
crc32          8 3d653119 
crc32b         8 3610a686 
haval128,3    32 85c3e4fac0ba4d85519978fdc3d1d9be 
haval160,3    40 0e53b29ad41cea507a343cdd8b62106864f6b3fe 
haval192,3    48 bfaf81218bbb8ee51b600f5088c4b8601558ff56e2de1c4f 
haval224,3    56 92d0e3354be5d525616f217660e0f860b5d472a9cb99d6766be 
haval256,3    64 26718e4fb05595cb8703a672a8ae91eea071cac5e7426173d4c 
haval128,4    32 fe10754e0b31d69d4ece9c7a46e044e5 
haval160,4    40 b9afd44b015f8afce44e4e02d8b908ed857afbd1 
haval192,4    48 ae73833a09e84691d0214f360ee5027396f12599e3618118 
haval224,4    56 e1ad67dc7a5901496b15dab92c2715de4b120af2baf661ecd92 
haval256,4    64 2d39577df3a6a63168826b2a10f07a65a676f5776a0772e0a87 
haval128,5    32 d20e920d5be9d9d34855accb501d1987 
haval160,5    40 dac5e2024bfea142e53d1422b90c9ee2c8187cc6 
haval192,5    48 bbb99b1e989ec3174019b20792fd92dd67175c2ff6ce5965 
haval224,5    56 aa6551d75e33a9c5cd4141e9a068b1fc7b6d847f85c3ab16295 
haval256,5    64 348298791817d5088a6de6c1b6364756d404a50bd64e645035f

The following hash algorithms should render 128-bit digests:

hash("md2", $text);
hash("md4", $text);
hash("md5", $text);
hash("ripemd128", $text);
hash("tiger128,3", $text);
hash("tiger128,4", $text);
hash("haval128,3", $text);
hash("haval128,4", $text);
hash("haval128,5", $text);

Those render 32 hexadecimal characters, each 1 nibble (4 bits):

          = 1/2417851639229258349412352 yottabyte
          = 1/2361183241434822606848 zettabyte
          = 1/2305843009213693952 exabyte
          = 1/2251799813685248 petabyte
          = 1/2199023255552 terabyte
          = 1/2147483648 gigabyte
          = 1/2097152 megabyte
          = 4/1048576 Megabit
          = 1/2048 kilobyte
          = 4/1024 Kilobit
          = 1/2 byte
   nibble = 1 nibble
          = 4 bits

32 X 4 = 128-bits

Example algorithm outputs:

<?php 
$data = "hello"; 

foreach (hash_algos() as $v) { 
        $r = hash($v, $data, false); 
        printf("%-12s %3d %s\n", $v, strlen($r), $r); 
} 
?> 

which produce (long hashes are cropped) 

md2           32 a9046c73e00331af68917d3804f70655                   
md4           32 866437cb7a794bce2b727acc0362ee27 
md5           32 5d41402abc4b2a76b9719d911017c592 
sha1          40 aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d 
sha256        64 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e730 
sha384        96 59e1748777448c69de6b800d7a33bbfb9ff1b463e44354c3553 
sha512       128 9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2d 
ripemd128     32 789d569f08ed7055e94b4289a4195012 
ripemd160     40 108f07b8382412612c048d07d13f814118445acd 
ripemd256     64 cc1d2594aece0a064b7aed75a57283d9490fd5705ed3d66bf9a 
ripemd320     80 eb0cf45114c56a8421fbcb33430fa22e0cd607560a88bbe14ce 
whirlpool    128 0a25f55d7308eca6b9567a7ed3bd1b46327f0f1ffdc804dd8bb 
tiger128,3    32 a78862336f7ffd2c8a3874f89b1b74f2 
tiger160,3    40 a78862336f7ffd2c8a3874f89b1b74f2f27bdbca 
tiger192,3    48 a78862336f7ffd2c8a3874f89b1b74f2f27bdbca39660254 
tiger128,4    32 1c2a939f230ee5e828f5d0eae5947135 
tiger160,4    40 1c2a939f230ee5e828f5d0eae5947135741cd0ae 
tiger192,4    48 1c2a939f230ee5e828f5d0eae5947135741cd0aefeeb2adc 
snefru        64 7c5f22b1a92d9470efea37ec6ed00b2357a4ce3c41aa6e28e3b 
gost          64 a7eb5d08ddf2363f1ea0317a803fcef81d33863c8b2f9f6d7d1 
adler32        8 062c0215 
crc32          8 3d653119 
crc32b         8 3610a686 
haval128,3    32 85c3e4fac0ba4d85519978fdc3d1d9be 
haval160,3    40 0e53b29ad41cea507a343cdd8b62106864f6b3fe 
haval192,3    48 bfaf81218bbb8ee51b600f5088c4b8601558ff56e2de1c4f 
haval224,3    56 92d0e3354be5d525616f217660e0f860b5d472a9cb99d6766be 
haval256,3    64 26718e4fb05595cb8703a672a8ae91eea071cac5e7426173d4c 
haval128,4    32 fe10754e0b31d69d4ece9c7a46e044e5 
haval160,4    40 b9afd44b015f8afce44e4e02d8b908ed857afbd1 
haval192,4    48 ae73833a09e84691d0214f360ee5027396f12599e3618118 
haval224,4    56 e1ad67dc7a5901496b15dab92c2715de4b120af2baf661ecd92 
haval256,4    64 2d39577df3a6a63168826b2a10f07a65a676f5776a0772e0a87 
haval128,5    32 d20e920d5be9d9d34855accb501d1987 
haval160,5    40 dac5e2024bfea142e53d1422b90c9ee2c8187cc6 
haval192,5    48 bbb99b1e989ec3174019b20792fd92dd67175c2ff6ce5965 
haval224,5    56 aa6551d75e33a9c5cd4141e9a068b1fc7b6d847f85c3ab16295 
haval256,5    64 348298791817d5088a6de6c1b6364756d404a50bd64e645035f
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文