【字符】Base64_解码

  勇芳 2017-4-5 6357

Function Base64Decode( ByVal  InBuff As String, ByVal  B64_Alpha As String) As String
    If B64_Alpha="" Then
        B64_Alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
    End If

    B64_Alpha="=" & B64_Alpha
    Local w1,w2,w3,w4,n,b As Long
    Local retry As String
    Local By() As Byte
    b = -1
       For n = 1 To Len(InBuff) Step 4
          w1 = Instr(B64_Alpha, Mid$(InBuff, n, 1)) - 2
          w2 = Instr(B64_Alpha, Mid$(InBuff, n + 1, 1)) - 2
          w3 = Instr(B64_Alpha, Mid$(InBuff, n + 2, 1)) - 2
          w4 = Instr(B64_Alpha, Mid$(InBuff, n + 3, 1)) - 2
            If w2 >= 0 Then
                b = b + 1: ReDim Preserve By(b)
                By(b) = (w1 * 4 + Int(w2 / 16)) And 255
            End If
            If w3 >= 0 Then
                b = b + 1: ReDim Preserve By(b)
                By(b) = (w2 * 16 + Int(w3 / 4)) And 255
            End If
            If w4 >= 0 Then
                b = b + 1: ReDim Preserve By(b)
                By(b) = (w3 * 64 + w4) And 255
            End If
    
       Next
    retry=Space$(UBound(by)+1)   
    FF_MemCopy  VarPtr(by(0)),StrPtr(retry) ,UBound(by)+1    
   Function = retry       'return the decoded string

End Function


因国家互联网安全管理要求,关闭回帖功能。大家需要留言,请使用【勇芳软件客服】即时联系勇芳点此打开->>勇芳软件客服
返回
联系勇芳
发新帖 搜索 反馈 回顶部