9

php中md5(‘许善祥’,true) 用ASP如何实现?

 3 years ago
source link: https://xushanxiang.com/2020/09/php-md5-true-asp.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

php中md5(‘许善祥’,true) 用ASP如何实现?

作者: xusx 分类: 其它 发布时间: 2020-09-12 22:21

一个朋友问的,是不是觉得很奇葩?有多少人用过md5函数的第二个参数?如今还有几人在用asp做东西?

有还是有的,估计90后基本排除在外,参见《ASP使用ajax来传递中文参数的编码处理》。

https://xushanxiang.com/2019/11/asp-ajax-escape.html

回到题目上来,我的想法是别实现了吧。

如果用于登录验证,是有严重漏洞的——《特定条件下的MD5验证绕过》(https://zhuanlan.zhihu.com/p/45946870)。

山不过来,我就过去,换个角度来思考。

如何得到不乱码的16位md5值呢?有两种方法:

  1. 对输出的16字节的二进制转化为十六进制;
  2. md5的密文中,16位密文与32位密文的第8-24位子字符串是一样的。

下面进入代码演示环节:

~./psysh
Psy Shell v0.7.2 (PHP 7.3.11 — cli) by Justin Hileman
>>> $name = '许善祥';
 => "许善祥"
>>> md5($name);
    => "9d979aa659fcd67311bc3f5e7340663d"
>>> substr(md5($name),8,16);
    => "59fcd67311bc3f5e"
>>> md5($name, true);
    => b"ØùܪY³Ís\x11╝?^s@f="
>>> bin2hex(md5($name, true));
    => "9d979aa659fcd67311bc3f5e7340663d"

看到了吧,是一样的,也就是用 php的bin2hex 函数把 ASCII 字符的字符串转换为十六进制值,asp就不要改和实现了,如果你实在很闲,那你就拿着下面的“古老”的VB代码借鉴一下,记得在留言里把结果告诉我。

'ASCII字符串转16进制字符串
Public Function A2H(str As String) As String
  Dim strlen As Integer
  Dim i As Integer
  Dim mystr As String
  mystr = ""
  strlen = Len(str)
  For i = 1 To strlen Step 1
    ' $类型说明符,表示Hex返回值是字符串
    mystr = mystr + Hex$(Asc(Mid(str, i, 1)))
  Next i
  A2H = mystr
End Function

如果觉得我的文章对您有用,请随意赞赏。您的支持将鼓励我继续创作!

发表评论 取消回复

电子邮件地址不会被公开。 必填项已用*标注


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK