到處是秘密
關於部落格
§所有節錄引用之圖片檔案照片文章影片,其著作所有權,均歸屬原著作人(公司)所有,若有不當節錄引用轉載之情況,請留言,會盡速摘下,謝謝!§
只要有心,天底下是沒有秘密的§自已動手,豐衣足食,神諭~有事沒事都要拜一下google大神§風啊! 大地啊! 天空啊~喵,我是喵喵的喵喵§
  • 105877

    累積人氣

  • 0

    今日人氣

    0

    訂閱人氣

base64Encode專對英數文字編碼

'ASP部分'將要參數帶入做編碼
Encode=Base64encode(empno)

Const sBASE_64_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

'ASP編碼的function
Function Base64encode(ByVal asContents)
Dim lnPosition
Dim lsResult
Dim Char1
Dim Char2
Dim Char3
Dim Char4
Dim Byte1
Dim Byte2
Dim Byte3
Dim SaveBits1
Dim SaveBits2
Dim lsGroupBinary
Dim lsGroup64

If Len(asContents) Mod 3 > 0 Then asContents = asContents & String(3 - (Len(asContents) Mod 3), " ")
lsResult = ""

For lnPosition = 1 To Len(asContents) Step 3
lsGroup64 = ""
lsGroupBinary = Mid(asContents, lnPosition, 3)

Byte1 = Asc(Mid(lsGroupBinary, 1, 1)): SaveBits1 = Byte1 And 3
Byte2 = Asc(Mid(lsGroupBinary, 2, 1)): SaveBits2 = Byte2 And 15
Byte3 = Asc(Mid(lsGroupBinary, 3, 1))

Char1 = Mid(sBASE_64_CHARACTERS, ((Byte1 And 252) 4) + 1, 1)
Char2 = Mid(sBASE_64_CHARACTERS, (((Byte2 And 240) 16) Or (SaveBits1 * 16) And &HFF) + 1, 1)
Char3 = Mid(sBASE_64_CHARACTERS, (((Byte3 And 192) 64) Or (SaveBits2 * 4) And &HFF) + 1, 1)
Char4 = Mid(sBASE_64_CHARACTERS, (Byte3 And 63) + 1, 1)
lsGroup64 = Char1 & Char2 & Char3 & Char4
lsResult = lsResult + lsGroup64
Next

Base64encode = lsResult
End Function


'ASP解碼的Function
Function Base64decode(ByVal asContents)
Dim lsResult
Dim lnPosition
Dim lsGroup64, lsGroupBinary
Dim Char1, Char2, Char3, Char4
Dim Byte1, Byte2, Byte3
If Len(asContents) Mod 4 > 0 Then asContents = asContents & String(4 - (Len(asContents) Mod 4), " ")
lsResult = ""

For lnPosition = 1 To Len(asContents) Step 4
lsGroupBinary = ""
lsGroup64 = Mid(asContents, lnPosition, 4)
Char1 = INSTR(sBASE_64_CHARACTERS, Mid(lsGroup64, 1, 1)) - 1
Char2 = INSTR(sBASE_64_CHARACTERS, Mid(lsGroup64, 2, 1)) - 1
Char3 = INSTR(sBASE_64_CHARACTERS, Mid(lsGroup64, 3, 1)) - 1
Char4 = INSTR(sBASE_64_CHARACTERS, Mid(lsGroup64, 4, 1)) - 1
Byte1 = Chr(((Char2 And 48) 16) Or (Char1 * 4) And &HFF)
Byte2 = lsGroupBinary & Chr(((Char3 And 60) 4) Or (Char2 * 16) And &HFF)
Byte3 = Chr((((Char3 And 3) * 64) And &HFF) Or (Char4 And 63))
lsGroupBinary = Byte1 & Byte2 & Byte3
lsResult = lsResult + lsGroupBinary
Next
Base64decode = lsResult
End Function


'.Net 在.aspx 做接參數碼解decode
byte[] encodedDataAsBytes = Convert.FromBase64String(Request.QueryString["empno"]);
decodestring = System.Text.Encoding.UTF8.GetString(encodedDataAsBytes);

'可以包入try catch避免不符合編碼的url參數導致錯誤



相簿設定
標籤設定
相簿狀態