'Base64 编码，B64_Alpha 哈希表可以自定
Function YF_Base64Encode(ByVal  InBuff as String, ByVal  B64_Alpha as String="=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/") as String 
    Dim as Long   C1 , C2 , c3 
    Dim as Long  w1 , w2 , w3 , w4 
    Dim as Integer n,Tu ,r   
    Dim OutBuff as String 
    Dim as UByte Ptr tS,bA,rE
    If Len(InBuff) =0 Then Exit Function
    If Len(B64_Alpha)< 64 Then Exit Function
      
     Tu = Len(InBuff)
     If Tu Mod 3 <> 0 Then  '需要3的倍数
        InBuff &= String(3 - (Tu  Mod 3),0)
     End If
     
     OutBuff=String(Len(InBuff)*4/3,0) '输出
     tS=StrPtr(InBuff)
     bA=StrPtr(B64_Alpha)
     rE=StrPtr(OutBuff)

     R = -1
       For n = 0 To Len(InBuff)-1 Step 3
          C1 = tS[n]
          C2 = tS[n+1]
          c3 = tS[n+2]

          w1 = Int(C1 / 4)
          w2 = (C1 And 3) * 16 + Int(C2 / 16)
          w3 = (C2 And 15) * 4 + Int(c3 / 64) + (n + 1 >= Tu)
          w4 = (c3 And 63) + (n + 2 >= Tu)
          R += 1: re[R] = Ba[w1 + 1]
          R += 1: re[R] = Ba[w2 + 1]
          R += 1: re[R] = Ba[w3 + 1]
          R += 1: re[R] = Ba[w4 + 1]
       Next
       Function = OutBuff
End Function