Chinaunix首页 | 论坛 | 博客
  • 博客访问: 579682
  • 博文数量: 190
  • 博客积分: 10937
  • 博客等级: 上将
  • 技术积分: 2205
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-07 11:28
文章分类

全部博文(190)

文章存档

2012年(1)

2011年(27)

2010年(20)

2009年(142)

我的朋友

分类:

2009-04-13 10:21:56

Function Base64Encode(inData As String) As String
    Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
    Dim cOut As String, sOut As String, i As Long
    Dim Bytes() As Byte
    Dim t As String
    Dim iLen As Long
    Dim sGroup As String
    t = StrConv(inData & "..", vbFromUnicode)
    Bytes = t
    iLen = UBound(Bytes) - 2
    Bytes(iLen + 1) = 0
    Bytes(iLen + 2) = 0
    sOut = ""
    For i = 0 To iLen Step 3
        sGroup = Oct(&H10000 * CLng(Bytes(i)) + &H100 * CLng(Bytes(i + 1)) + Bytes(i + 2))
        sGroup = String(8 - Len(sGroup), "0") & sGroup
        sOut = sOut + Mid(Base64, CLng("&o" & Mid(sGroup, 1, 2)) + 1, 1) + Mid(Base64, CLng("&o" & Mid(sGroup, 3, 2)) + 1, 1) + Mid(Base64, CLng("&o" & Mid(sGroup, 5, 2)) + 1, 1) + Mid(Base64, CLng("&o" & Mid(sGroup, 7, 2)) + 1, 1)
    Next
    Select Case iLen Mod 3
        Case 0:
            sOut = Left(sOut, Len(sOut) - 2) + "=="
        Case 1:
            sOut = Left(sOut, Len(sOut) - 1) + "="
    End Select
    Base64Encode = sOut
End Function
阅读(1241) | 评论(0) | 转发(0) |
0

上一篇:StrToByte

下一篇:ShellExecute

给主人留下些什么吧!~~