base64 - Descrypt SagePay string vb.net -


i have been having problems trying decrypt string returned sagepay.

i used asp.net kit included encrypt , decrypt functions using base64 - sending information sagepay not problem having number of problems trying descrypt string.

here function using descypt:

private function base64decode(byval strencoded string) string

    dim ireallength integer     dim strreturn string     dim iby4 integer     dim iindex integer     dim ifirst integer     dim isecond integer     dim ithird integer     dim ifourth integer     if len(strencoded) = 0         base64decode = ""         exit function     end if      '** base 64 encoded strings right padded 3 character multiples using = signs **     '** work out actual length of data without padding here **     ireallength = len(strencoded)     while mid(strencoded, ireallength, 1) = "="         ireallength = ireallength - 1     loop      '** non standard extension base 64 decode allow + sign space character substitution **     '** web servers. base 64 expects +, not space, convert vack + if space found **     while instr(strencoded, " ") <> 0         strencoded = left(strencoded, instr(strencoded, " ") - 1) & "+" & mid(strencoded, instr(strencoded, " ") + 1)     loop      strreturn = ""     '** convert base 64 4x6 byte values 3x8 byte real values reading 4 chars @ time **     iby4 = (ireallength \ 4) * 4     iindex = 1     while iindex <= iby4         ifirst = arrbase64decmap(asc(mid(strencoded, iindex + 0, 1)))         'ifirst = ctype(system.convert.tobyte(ctype(mid(strencoded, iindex + 0, 1), char)), integer)         isecond = arrbase64decmap(asc(mid(strencoded, iindex + 1, 1)))         'isecond = ctype(system.convert.tobyte(ctype(mid(strencoded, iindex + 1, 1), char)), integer)         ithird = arrbase64decmap(asc(mid(strencoded, iindex + 2, 1)))         'ithird = ctype(system.convert.tobyte(ctype(mid(strencoded, iindex + 2, 1), char)), integer)         ifourth = arrbase64decmap(asc(mid(strencoded, iindex + 3, 1)))         'ifourth = ctype(system.convert.tobyte(ctype(mid(strencoded, iindex + 3, 1), char)), integer)         strreturn = strreturn + ctype(system.convert.tochar(((ifirst * 4) , 255) + ((isecond \ 16) , 3)), string) 'chr(((ifirst * 4) , 255) + ((isecond \ 16) , 3))         strreturn = strreturn + ctype(system.convert.tochar(((isecond * 16) , 255) + ((ithird \ 4) , 15)), string) 'chr(((isecond * 16) , 255) + ((ithird \ 4) , 15))         strreturn = strreturn + ctype(system.convert.tochar(((ithird * 64) , 255) + (ifourth , 63)), string) 'chr(((ithird * 64) , 255) + (ifourth , 63))         iindex = iindex + 4     loop      '** non multiples of 4 characters, handle = padding **     if iindex < ireallength         ifirst = arrbase64decmap(asc(mid(strencoded, iindex + 0, 1)))         isecond = arrbase64decmap(asc(mid(strencoded, iindex + 1, 1)))         strreturn = strreturn & chr(((ifirst * 4) , 255) + ((isecond \ 16) , 3))         if ireallength mod 4 = 3             ithird = arrbase64decmap(asc(mid(strencoded, iindex + 2, 1)))             strreturn = strreturn & chr(((isecond * 16) , 255) + ((ithird \ 4) , 15))         end if     end if      base64decode = strreturn end function 

i don't think web server trying encode there no + symbols within url string , have glanced on 2 compair same.

this returns blank string whereas when use sections commented out in first loop weired string , when use simplexor function returns complete nonsense.

there support bit useless "are not programmers"! hoping can me out has used sagepay before.

thanks in advance.

managed working:

private function base64decode(byval strencoded string) string      dim output string = ""      dim bt64 byte() = system.convert.frombase64string(strencoded)       integer = 0 (bt64.length - 1)          output &= system.convert.tochar(cint(bt64(i))).tostring()      next       return output  end function 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

sql server - python to mssql encoding problem -

windows - Python Service Installation - "Could not find PythonClass entry" -