ASP下使用md5加密註冊資訊

來源:互聯網
上載者:User
加密

製作登陸行為時可能需要用到MD5加密使用者密碼,使用ASP實現這個功能比其他語言稍微麻煩一點,但是也是可行的.

核心代碼:

<%
PrivateConstBITS_TO_A_BYTE=8
PrivateConstBYTES_TO_A_WORD=4
PrivateConstBITS_TO_A_WORD=32

Privatem_lOnBits(30)
Privatem_l2Power(30)

PrivateFunctionLShift(lValue,iShiftBits)
 IfiShiftBits=0Then
   LShift=lValue
   ExitFunction
 ElseIfiShiftBits=31Then
   IflValueAnd1Then
     LShift=&H80000000
   Else
     LShift=0
   EndIf
   ExitFunction
 ElseIfiShiftBits<0OriShiftBits>31Then
   Err.Raise6
 EndIf

 If(lValueAndm_l2Power(31-iShiftBits))Then
   LShift=((lValueAndm_lOnBits(31-(iShiftBits+1)))*m_l2Power(iShiftBits))Or&H80000000
 Else
   LShift=((lValueAndm_lOnBits(31-iShiftBits))*m_l2Power(iShiftBits))
 EndIf
EndFunction

PrivateFunctionRShift(lValue,iShiftBits)
 IfiShiftBits=0Then
   RShift=lValue
   ExitFunction
 ElseIfiShiftBits=31Then
   IflValueAnd&H80000000Then
     RShift=1
   Else
     RShift=0
   EndIf
   ExitFunction
 ElseIfiShiftBits<0OriShiftBits>31Then
   Err.Raise6
 EndIf
 
 RShift=(lValueAnd&H7FFFFFFE) m_l2Power(iShiftBits)

 If(lValueAnd&H80000000)Then
   RShift=(RShiftOr(&H40000000 m_l2Power(iShiftBits-1)))
 EndIf
EndFunction

PrivateFunctionRotateLeft(lValue,iShiftBits)
 RotateLeft=LShift(lValue,iShiftBits)OrRShift(lValue,(32-iShiftBits))
EndFunction

PrivateFunctionAddUnsigned(lX,lY)
 DimlX4
 DimlY4
 DimlX8
 DimlY8
 DimlResult

 lX8=lXAnd&H80000000
 lY8=lYAnd&H80000000
 lX4=lXAnd&H40000000
 lY4=lYAnd&H40000000

 lResult=(lXAnd&H3FFFFFFF)+(lYAnd&H3FFFFFFF)

 IflX4AndlY4Then
   lResult=lResultXor&H80000000XorlX8XorlY8
 ElseIflX4OrlY4Then
   IflResultAnd&H40000000Then
     lResult=lResultXor&HC0000000XorlX8XorlY8
   Else
     lResult=lResultXor&H40000000XorlX8XorlY8
   EndIf
 Else
   lResult=lResultXorlX8XorlY8
 EndIf

 AddUnsigned=lResult
EndFunction

PrivateFunctionmd5_F(x,y,z)
 md5_F=(xAndy)Or((Notx)Andz)
EndFunction

PrivateFunctionmd5_G(x,y,z)
 md5_G=(xAndz)Or(yAnd(Notz))
EndFunction

PrivateFunctionmd5_H(x,y,z)
 md5_H=(xXoryXorz)
EndFunction

PrivateFunctionmd5_I(x,y,z)
 md5_I=(yXor(xOr(Notz)))
EndFunction

PrivateSubmd5_FF(a,b,c,d,x,s,ac)
 a=AddUnsigned(a,AddUnsigned(AddUnsigned(md5_F(b,c,d),x),ac))
 a=RotateLeft(a,s)
 a=AddUnsigned(a,b)
EndSub

PrivateSubmd5_GG(a,b,c,d,x,s,ac)
 a=AddUnsigned(a,AddUnsigned(AddUnsigned(md5_G(b,c,d),x),ac))
 a=RotateLeft(a,s)
 a=AddUnsigned(a,b)
EndSub

PrivateSubmd5_HH(a,b,c,d,x,s,ac)
 a=AddUnsigned(a,AddUnsigned(AddUnsigned(md5_H(b,c,d),x),ac))
 a=RotateLeft(a,s)
 a=AddUnsigned(a,b)
EndSub

PrivateSubmd5_II(a,b,c,d,x,s,ac)
 a=AddUnsigned(a,AddUnsigned(AddUnsigned(md5_I(b,c,d),x),ac))
 a=RotateLeft(a,s)
 a=AddUnsigned(a,b)
EndSub

PrivateFunctionConvertToWordArray(sMessage)
 DimlMessageLength
 DimlNumberOfWords
 DimlWordArray()
 DimlBytePosition
 DimlByteCount
 DimlWordCount
 
 ConstMODULUS_BITS=512
 ConstCONGRUENT_BITS=448
 
 lMessageLength=Len(sMessage)
 
 lNumberOfWords=(((lMessageLength+((MODULUS_BITS-CONGRUENT_BITS) BITS_TO_A_BYTE)) (MODULUS_BITS BITS_TO_A_BYTE))+1)*(MODULUS_BITS BITS_TO_A_WORD)
 ReDimlWordArray(lNumberOfWords-1)
 
 lBytePosition=0
 lByteCount=0
 DoUntillByteCount>=lMessageLength
   lWordCount=lByteCount BYTES_TO_A_WORD
   lBytePosition=(lByteCountModBYTES_TO_A_WORD)*BITS_TO_A_BYTE
   lWordArray(lWordCount)=lWordArray(lWordCount)OrLShift(Asc(Mid(sMessage,lByteCount+1,1)),lBytePosition)
   lByteCount=lByteCount+1
 Loop

 lWordCount=lByteCount BYTES_TO_A_WORD
 lBytePosition=(lByteCountModBYTES_TO_A_WORD)*BITS_TO_A_BYTE

 lWordArray(lWordCount)=lWordArray(lWordCount)OrLShift(&H80,lBytePosition)

 lWordArray(lNumberOfWords-2)=LShift(lMessageLength,3)
 lWordArray(lNumberOfWords-1)=RShift(lMessageLength,29)

相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。