2011-01-25 6 views
0

私は、SagePayから返された文字列を解読しようとするといくつかの問題を抱えています。Describe SagePay string vb.net

base64を使用して暗号化と復号化機能を含むasp.netキットを使用しました.SagePayに情報を送信することは問題ではありませんが、文字列を暗号化解除する際に問題が発生しています。ここで

は私がdescyptするために使用しています関数です。

Private Function base64Decode(ByVal strEncoded As String) As String

Dim iRealLength As Integer 
    Dim strReturn As String 
    Dim iBy4 As Integer 
    Dim iIndex As Integer 
    Dim iFirst As Integer 
    Dim iSecond As Integer 
    Dim iThird As Integer 
    Dim iFourth As Integer 
    If Len(strEncoded) = 0 Then 
     base64Decode = "" 
     Exit Function 
    End If 

    '** Base 64 encoded strings are right padded to 3 character multiples using = signs ** 
    '** Work out the actual length of data without the padding here ** 
    iRealLength = Len(strEncoded) 
    Do While Mid(strEncoded, iRealLength, 1) = "=" 
     iRealLength = iRealLength - 1 
    Loop 

    '** Non standard extension to Base 64 decode to allow for + sign to space character substitution by ** 
    '** some web servers. Base 64 expects a +, not a space, so convert vack to + if space is found ** 
    Do While InStr(strEncoded, " ") <> 0 
     strEncoded = Left(strEncoded, InStr(strEncoded, " ") - 1) & "+" & Mid(strEncoded, InStr(strEncoded, " ") + 1) 
    Loop 

    strReturn = "" 
    '** Convert the base 64 4x6 byte values into 3x8 byte real values by reading 4 chars at a time ** 
    iBy4 = (iRealLength \ 4) * 4 
    iIndex = 1 
    Do 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) And 255) + ((iSecond \ 16) And 3)), String) 'Chr(((iFirst * 4) And 255) + ((iSecond \ 16) And 3)) 
     strReturn = strReturn + CType(System.Convert.ToChar(((iSecond * 16) And 255) + ((iThird \ 4) And 15)), String) 'Chr(((iSecond * 16) And 255) + ((iThird \ 4) And 15)) 
     strReturn = strReturn + CType(System.Convert.ToChar(((iThird * 64) And 255) + (iFourth And 63)), String) 'Chr(((iThird * 64) And 255) + (iFourth And 63)) 
     iIndex = iIndex + 4 
    Loop 

    '** For non multiples of 4 characters, handle the = padding ** 
    If iIndex < iRealLength Then 
     iFirst = arrBase64DecMap(Asc(Mid(strEncoded, iIndex + 0, 1))) 
     iSecond = arrBase64DecMap(Asc(Mid(strEncoded, iIndex + 1, 1))) 
     strReturn = strReturn & Chr(((iFirst * 4) And 255) + ((iSecond \ 16) And 3)) 
     If iRealLength Mod 4 = 3 Then 
      iThird = arrBase64DecMap(Asc(Mid(strEncoded, iIndex + 2, 1))) 
      strReturn = strReturn & Chr(((iSecond * 16) And 255) + ((iThird \ 4) And 15)) 
     End If 
    End If 

    base64Decode = strReturn 
End Function 

何の+記号は、URL文字列の中に存在しないように私は、Webサーバーが何かをエンコードしようとしているとは思わないし、私は持っていますそれらを比較するために2つを見渡し、それらは同じである。

これは空白の文字列を返しますが、最初のループでコメントアウトされたセクションを使用すると、本当に元気づけられた文字列が戻ってくるので、simpleXor関数を使用すると完全なナンセンスが返されます。

「プログラマーではない」ため、サポートは少し役に立たないです!だから私は誰かがSagePayを以前に使った人を助けてくれることを願っています。

ありがとうございます。

答えて

1

は、それが働いて得ることができた:

Private Function base64Decode(ByVal strEncoded As String) As String 
    Dim output As String = "" 
    Dim bt64 As Byte() = System.Convert.FromBase64String(strEncoded) 

    For i As Integer = 0 To (bt64.Length - 1) 
     output &= System.Convert.ToChar(CInt(bt64(i))).ToString() 
    Next 

    Return output 
End Function