Public Function Base64Decode(cString As String) As String 'QQ版Base64解码
Dim dStr As String, tStr As String
Dim i As Integer
Dim l As Integer
l = Len(cString) - 2 '减去两个等号的空间(不减也行)
For i = 1 To l
dStr = HexBase64_1(Mid(cString, i, 1))
tStr = tStr & Hex2Bin(Left(dStr, 1)) & Hex2Bin(Right(dStr, 1))
Next i
l = Len(tStr)
dStr = ""
For i = 3 To l Step 8
dStr = dStr & Mid(tStr, i, 6)
Next i
l = Len(dStr)
For i = 1 To l Step 4
Base64Decode = Base64Decode & Bin2Hex(Mid(dStr, i, 4))
Next i
If Len(Base64Decode) > 32 Then Base64Decode = Left(Base64Decode, 32)
End Function
Private Function Bin2Hex(BinStr1 As String) As String
Select Case BinStr1
'2进制转换16进制
Case "0000": Bin2Hex = "0"
Case "0001": Bin2Hex = "1"
Case "0010": Bin2Hex = "2"
Case "0011": Bin2Hex = "3"
Case "0100": Bin2Hex = "4"
Case "0101": Bin2Hex = "5"
Case "0110": Bin2Hex = "6"
Case "0111": Bin2Hex = "7"
Case "1000": Bin2Hex = "8"
Case "1001": Bin2Hex = "9"
Case "1010": Bin2Hex = "a"
Case "1011": Bin2Hex = "b"
Case "1100": Bin2Hex = "c"
Case "1101": Bin2Hex = "d"
Case "1110": Bin2Hex = "e"
Case "1111": Bin2Hex = "f"
End Select
End Function
Private Function Hex2Bin(HexStr1 As String) As String
Select Case UCase(HexStr1)
'16进制转换二进制
Case "0": Hex2Bin = "0000"
Case "1": Hex2Bin = "0001"
Case "2": Hex2Bin = "0010"
Case "3": Hex2Bin = "0011"
Case "4": Hex2Bin = "0100"
Case "5": Hex2Bin = "0101"
Case "6": Hex2Bin = "0110"
Case "7": Hex2Bin = "0111"
Case "8": Hex2Bin = "1000"
Case "9": Hex2Bin = "1001"
Case "A": Hex2Bin = "1010"
Case "B": Hex2Bin = "1011"
Case "C": Hex2Bin = "1100"
Case "D": Hex2Bin = "1101"
Case "E": Hex2Bin = "1110"
Case "F": Hex2Bin = "1111"
End Select
End Function
Private Function HexBase64_1(HexString As String) As String
Select Case HexString
Case "A": HexBase64_1 = "00"
Case "B": HexBase64_1 = "01"
Case "C": HexBase64_1 = "02"
Case "D": HexBase64_1 = "03"
Case "E": HexBase64_1 = "04"
Case "F": HexBase64_1 = "05"
Case "G": HexBase64_1 = "06"
Case "H": HexBase64_1 = "07"
Case "I": HexBase64_1 = "08"
Case "J": HexBase64_1 = "09"
Case "K": HexBase64_1 = "0A"
Case "L": HexBase64_1 = "0B"
Case "M": HexBase64_1 = "0C"
Case "N": HexBase64_1 = "0D"
Case "O": HexBase64_1 = "0E"
Case "P": HexBase64_1 = "0F"
Case "Q": HexBase64_1 = "10"
Case "R": HexBase64_1 = "11"
Case "S": HexBase64_1 = "12"
Case "T": HexBase64_1 = "13"
Case "U": HexBase64_1 = "14"
Case "V": HexBase64_1 = "15"
Case "W": HexBase64_1 = "16"
Case "X": HexBase64_1 = "17"
Case "Y": HexBase64_1 = "18"
Case "Z": HexBase64_1 = "19"
Case "a": HexBase64_1 = "1A"
Case "b": HexBase64_1 = "1B"
Case "c": HexBase64_1 = "1C"
Case "d": HexBase64_1 = "1D"
Case "e": HexBase64_1 = "1E"
Case "f": HexBase64_1 = "1F"
Case "g": HexBase64_1 = "20"
Case "h": HexBase64_1 = "21"
Case "i": HexBase64_1 = "22"
Case "j": HexBase64_1 = "23"
Case "k": HexBase64_1 = "24"
Case "l": HexBase64_1 = "25"
Case "m": HexBase64_1 = "26"
Case "n": HexBase64_1 = "27"
Case "o": HexBase64_1 = "28"
Case "p": HexBase64_1 = "29"
Case "q": HexBase64_1 = "2A"
Case "r": HexBase64_1 = "2B"
Case "s": HexBase64_1 = "2C"
Case "t": HexBase64_1 = "2D"
Case "u": HexBase64_1 = "2E"
Case "v": HexBase64_1 = "2F"
Case "w": HexBase64_1 = "30"
Case "x": HexBase64_1 = "31"
Case "y": HexBase64_1 = "32"
Case "z": HexBase64_1 = "33"
Case "0": HexBase64_1 = "34"
Case "1": HexBase64_1 = "35"
Case "2": HexBase64_1 = "36"
Case "3": HexBase64_1 = "37"
Case "4": HexBase64_1 = "38"
Case "5": HexBase64_1 = "39"
Case "6": HexBase64_1 = "3A"
Case "7": HexBase64_1 = "3B"
Case "8": HexBase64_1 = "3C"
Case "9": HexBase64_1 = "3D"
Case "+": HexBase64_1 = "3E"
Case "/": HexBase64_1 = "3F"
End Select
End Function