Pergunta

Is there a way to make this work in an ASP page? It was working fine with charset windows-1253 but now I have to convert my site to UTF-8 and the only problem I have is encryption and decryption. I have encrypted members registration passwords and now with UTF-8, after decryption passwords looks like this: 2��8��6

Please I nead some help (sorry for my English). This is RC4 code:

Dim sbox(255)
   Dim rc4Key(255)

   Sub RC4Initialize(strPwd)

      dim tempSwap, a, b      

      intLength = len(strPwd)

      for a = 0 To 255

         rc4Key(a)  = asc(mid(strpwd, (a mod intLength)+1, 1))

         sbox(a) = a                       
      next

      b = 0

      for a = 0 To 255
         b = (b + sbox(a) + rc4Key(a)) Mod 256         
         tempSwap = sbox(a)
         sbox(a) = sbox(b)
         sbox(b) = tempSwap
      Next

   End Sub

   function EnDeCrypt(plaintxt, psw)      

      dim temp, a, i, j, k, cipherby, cipher      

      i = 0
      j = 0

      RC4Initialize psw

      for a = 1 To Len(plaintxt)
         i  = (i + 1) Mod 256
         j  = (j + sbox(i)) Mod 256
         temp   = sbox(i)
         sbox(i)= sbox(j)
         sbox(j)= temp

         k  = sbox((sbox(i) + sbox(j)) Mod 256)

         cipherby   = Asc(Mid(plaintxt, a, 1)) Xor k
         cipher     = cipher & Chr(cipherby)         
      next

      enDeCrypt = cipher            

   end function

   function RC4EnCryptASC(plaintxt, psw)      

      dim temp, a, i, j, k, cipherby, cipher      

      i = 0
      j = 0

      RC4Initialize psw

      for a = 1 To Len(plaintxt)
         i  = (i + 1) Mod 256
         j  = (j + sbox(i)) Mod 256
         temp   = sbox(i)
         sbox(i)= sbox(j)
         sbox(j)= temp

         k      = sbox((sbox(i) + sbox(j)) Mod 256)

         cipherby   = Asc(Mid(plaintxt, a, 1)) Xor k         
         cipher     = cipher & "|"& cipherby         
      next            

      RC4EnCryptASC = cipher            

   end function

   function RC4DeCryptASC(plaintxt, psw)      

      plaintxt = transformToCHR(plaintxt)

      dim temp, a, i, j, k, cipherby, cipher      

      i = 0
      j = 0      

      dim arrayEncrypted            

      RC4Initialize psw         

       for a = 1 To Len(plaintxt)
         i  = (i + 1) Mod 256
         j  = (j + sbox(i)) Mod 256
         temp   = sbox(i)
         sbox(i)= sbox(j)
         sbox(j)= temp

         k  = sbox((sbox(i) + sbox(j)) Mod 256)

         cipherby   = Asc(Mid(plaintxt, a, 1)) Xor k
         cipher     = cipher & Chr(cipherby)         
      next

      RC4DeCryptASC = cipher                       

   end function

function transformToCHR(plaintxt)


      dim returnText, arrayEncrypted
      arrayEncrypted = split(plaintxt, "|")            

      returnText=""            

      for a = 1 to ubound(arrayEncrypted)         
         returnText=returnText&CHR(arrayEncrypted(a))         
      next            

      transformToCHR = returnText
end function
Foi útil?

Solução

i think you have to use AscW function and the equivalent other functions to deal with Unicode characters?

Outras dicas

Ok finally I made it. I just replaced each asc to ascW and each chr to chrW and it works perfect.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top