Search the web
Sign In
New User? Sign Up
active-server-pages · Active Server Pages Developers' List
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want your group to be featured on the Yahoo! Groups website? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
RC4 Encryption   Message List  
Reply | Forward Message #12382 of 12411 |
Hey guys

Anyone still around here?

I have an issue that's really been messing with my head!

I have a ready-made function for RC4 encryption.
Then it converted to Hex for storing in an SQL db (see below).

The very weird thing, is that when in the order process, the
encryption/decrypt process is perfect.

But when I access the same string, using the same functions, with the same
key, via an admin interface I built the credit card info that spits out - is
wrong. There is some kind of a corruption. I have managed to find a pattern
where things are corrupt in the hex-based encrypted string, and can fix it,
But I'm really at a loss why the same string, same functions and same key
can give different results.

For example, when I display the open full CC number in the admin site, i
get: 11&11111&&111&16
but the correct number converted using the same functions and stored
directly in the database, is: 1111111111111111 (and this is viewable during
the actual order process too, when we confirm payment details after
encryption).

Does anyone have any ideas why this might happen?


Thanks!
Moshe


'==========================================================

CODE:

ENCRYPTION CODE: EncryptedCCnumber =
Ascii2Hex(EnDeCrypt(FullCCnumber,mykey))

DECRYPTION CODE: FullCCnumber =
EnDeCrypt(Hex2Ascii(EncryptedCCnumber),mykey)



'FUNCTIONS:

Function EnDeCrypt(plaintxt, psw)

'If plaintext is empty, return Empty String
if isEmpty(plaintxt) or isNull(plaintxt) or plaintxt = "" then
EnDeCrypt = ""
exit function
end if


'Declare Variables
dim sbox(255), key(255)
dim temp, tempSwap, intLength
dim a, b, i, j, k
dim cipherby, cipher

'Initialize some variables
b = 0
i = 0
j = 0

'Initialize sbox and key array
intLength = len(psw)
For a = 0 To 255
key(a) = asc(mid(psw, (a mod intLength)+1, 1))
sbox(a) = a
next
For a = 0 To 255
b = (b + sbox(a) + key(a)) Mod 256
tempSwap = sbox(a)
sbox(a) = sbox(b)
sbox(b) = tempSwap
Next

'Encrypt/Decrypt text
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
'******************************************************************
'Convert a String to Hex values
'******************************************************************
function Ascii2Hex(strTemp)
if strTemp = "" or isNull(strTemp) then
Ascii2Hex = ""
else
dim I
for I = 1 to len(strTemp)
Ascii2Hex = Ascii2Hex & right("00" &
hex(asc(mid(strTemp,I,1))),2)
next
end if
end function
'******************************************************************
'Convert a Hex values to String
'******************************************************************
function Hex2Ascii(strTemp)
if strTemp = "" or isNull(strTemp) then
Hex2Ascii = ""
else
dim I
for I = 1 to len(strTemp) step 2
Hex2Ascii = Hex2Ascii & Chr(Eval("&H" &
Mid(strTemp,I,2)))
next
end if
end function









Sun Apr 19, 2009 10:57 pm

tapnack
Offline Offline
Send Email Send Email

Forward
Message #12382 of 12411 |
Expand Messages Author Sort by Date

Hey guys Anyone still around here? I have an issue that's really been messing with my head! I have a ready-made function for RC4 encryption. Then it converted...
Moshe Tapnack
tapnack
Offline Send Email
Apr 19, 2009
10:57 pm

Hi Moshe, ... Yep. :) ... Sounds like it's one of either two problems: * The characters in the first implementation are a different charset than in the second...
Shawn K. Hall
shawn_ra
Online Now Send Email
Apr 20, 2009
2:49 am

Hey Shawn Good to hear from you! And especially with as detailed a reply! Both interfaces are UTF8, but I will check what the database is. I assume that that...
Moshe Tapnack
tapnack
Offline Send Email
Apr 20, 2009
9:34 pm

Hey there I have a script that should download a CSV file from the browser. It works perfectly on Firefox and Chrome - but on IE(v7) it chokes and throws and ...
Moshe Tapnack
tapnack
Offline Send Email
May 5, 2009
7:00 pm

You're getting an IE error, but have shown a script that we are not going to be able to run. This is not going to allow analysis. What you need to provide is...
David Smart
smartware_co...
Offline Send Email
May 5, 2009
9:48 pm

Hi Dave There is no HTML - it's a purely ASP server side page - its responsing to the CSV file. And in FF the script works perfectly anyway... ... From:...
Moshe Tapnack
tapnack
Offline Send Email
May 5, 2009
10:54 pm

Hi Moshe, Change this: Response.ContentType = "text/csv" To this: Response.ContentType = "application/x-msdownload" This is the only way to consistently...
Shawn K. Hall
shawn_ra
Online Now Send Email
May 6, 2009
3:40 am

Hi Shawn A VERY belated thank you for this reply - I was away on reserve duty, vacation, and a little work time in-between the 2... and I have just tried this...
Moshe Tapnack
tapnack
Offline Send Email
Aug 9, 2009
3:03 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help