ASP下使用md5加密注册信息

80酷酷网    80kuku.com

  加密

制作登陆行为时可能需要用到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)

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: