Using MD5 to encrypt registration information under ASP

Source: Internet
Author: User
Tags md5
Encryption

It may be necessary to use the MD5 to encrypt the user password when making the login behavior, which is a little more troublesome than other languages, but it is also feasible.

Core code:

<%
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= (XOr yxor (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)
&NBSP
 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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.