时间: 2021-07-31 作者:daque
关于asp,asp.net,VB.NET里的MD5加密函数 在asp中,咱们运用过如动网乒坛等用的asp中md5因变量加密出的字符串则如: 1165d25d8cd021d5 而在asp.net中底下的本领: 代码 system.web.security.formsauthentication.hashpasswordforstoringinconfigfile(password.text,"md5")举行md5加密出来的截止却是: 12c403b91165d25d8cd021d5f9b5bb7f 究其因为,是由于,在asp中的md5因变量是运用了32位md5 hashvalue中的第9~25位再变小写稿为密文。领会这个因为,把asp.net的截止稍加处置就不妨用来比拟老数据库中的暗号字串了。 在asp的md5因变量中第353、354行: 代码 ´md5 = lcase(wordtohex(a) & wordtohex(b) & wordtohex(c) & wordtohex(d)) md5=lcase(wordtohex(b) & wordtohex(c)) ´i crop this to fit 16byte database password :d 第一句是取十足的32位密文,第二句则是取中央第9~25位为16位密文。 到了vb.net题目又来了,在vb.net里,没辙用到system.web.security称呼空间,没辙用上头大略的方法举行md5加密。故我写了底下这个因变量来处置: vb.net: 代码´md5 加密因变量 public shared function md5(byval strsource as string, byval code as int16) as string ´这边用的是ascii源代码暗号原文,即使要用中国字做暗号,不妨用unicodeencoding,但会与asp中的md5因变量不兼容 dim datatohash as byte() = (new system.text.asciiencoding).getbytes(strsource) dim hashvalue as byte() = ctype(system.security.cryptography.cryptoconfig.createfromname("md5"), system.security.cryptography.hashalgorithm).computehash(datatohash) dim i as integer select case code case 16 ´采用16位字符的加密截止 for i = 4 to 11 md5 += hex(hashvalue(i)).tolower next case 32 ´采用32位字符的加密截止 for i = 0 to 15 md5 += hex(hashvalue(i)).tolower next case else ´code缺点时,归来十足字符串,即32位字符 for i = 0 to hashvalue.length - 1 md5 += hex(hashvalue(i)).tolower next end select end function