rc4加密 java,RC4加密和解密使用UTF-8的ASP经典

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

解决方案

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值