核心**:
www.cppcns.com456789+/"
dim newline
dim base64encmap(63)
dim base64decmap(127)
'初始化函式
public sub initcodecs()
' 初始化變數
newline = "" & chr(13) & chr(10)
dim max, idx
max = len(base_64_map_init)
for idx = 0 to max - 1
base64encmap(idx) = mid(base_64_map_init, idx + 1, 1)
next
for idx = 0 to max - 1
base64decmap(asc(base64encmap(idx))) = idx
next
end sub
'base64加密函式
public function base64encode(plain)
if len(plain) = 0 then
base64encode = ""
exit function
end if
dim ret, ndx, by3, first, second, third
by3 = (len(plain) \ 3) * 3
ndx = 1
do while ndx <= by3
first = asc(mid(plain, ndx+0, 1))
second = asc(mid(plain, ndx+1, 1))
third = asc(mid(plain, ndx+2, 1))
ret = ret & base64encmap( (first \ 4) and 63 )
ret = ret & base64encmap( ((first * 16) and 48) + ((second \ 16) and 15 ) )
ret = ret & base64encmap( ((second * 4) and 60) + ((third \ 64) and 3 ) )
ret = ret & base64encmap( third and 63)
ndx = ndx + 3
loop
if by3 < len(plain) then
first = asc(mid(plain, ndx+0, 1))
ret = ret & base64encmap( (first \ 4) and 63 )
if (len(plain) mod 3 ) = 2 then
second = asc(mid(plain, ndx+1, 1))
ret = ret & base64encmap( ((first * 16) and 48) + ((second \ 16) and 15 ) )
ret = ret & base64encmap( ((second * 4) and 60) )
else
ret = ret & base64encmap( ( * 16) and 48)
ret = ret '& "="
end if
ret = ret '& "="
end if
程式設計客棧 base64encode = ret
end function
'base64解密函式
public function base64decode(scrambled)
if len(scrambled) = 0 then
base64decode = ""
exit function
end if
dim reallen
reallen = len(scrambled)
do while mid(scrambled, reallen, 1) = "="
reallen = reallen - 1
loop
dim ret, ndx, by first, second, third, fourth
ret = ""
by4 = (reallen \ 4) * 4
ndx = 1
do while ndx <= by4
first = base64decmap(asc(mid(scrambled, ndx+0, 1)))
second = base64decmap(asc(mid(scrambled, ndx+1, 1)))
third = base64decmap(asc(mid(scrambled, ndx+2, 1)))
fourth = base64decmap(asc(mid(scrambled, ndx+3, 1)))
ret = ret & chr( ((first * 4) and 255) + ((second \ 16) and 3))
ret = ret & chr( ((second * 16) and 255) + ((third \ 4) and 15))
ret = ret & chr( ((third * 64) and 255) + (fourth and 63))
ndx = ndx + 4
loop
if ndx < reallen then
first = base64decmap(asc(mid(scrambled, ndx+0, 1)))
second = ndx+1, 1)))
ret = ret & chr( ((first * 4) and 255) + ((second \ 16) and 3))
if reallen mod 4 = 3 then
third = base64decmap(asc(mid(scrambled,ndx+2,1)))
ret = ret & chr( ((second * 16) and 255) + ((third \ 4) and 15))
end if
end if
base64decode = ret
end function
%>
使用方法:
' 初始化
call initcodecs
response.write(base64encode("我們之我要加密的字串"))
response.write(base64decode("bwfycziwmtawmjiw0"))
本文標題: asp base64加解密(親測可用)
本文位址:
php base64編碼 加解密 手動實現
base64編碼原理 gb 2312 字符集是目前最常用的漢字編碼標準。在這個標準中,每個漢字用2個位元組來表示,每個位元組的ascii碼為 161 254 16 進製a1 fe 第乙個位元組 對應於 區碼的1 94 區,第二個位元組 對應於位碼的1 94 位。漢字的unicode 編碼範圍為 u4...
Base64編譯碼原理及AES加解密演算法的使用
base64編譯碼 1英文本元 1位元組 8位 base64編碼原理 將要編碼的二進位制 字串 等都可以轉換成二進位制格式表示 把3個8位位元組以4個6位的位元組表示,然後把每個6位位元組都轉換成乙個單獨的數字並對映到base64碼表中的乙個字元。如果最後剩下的位元組不足3個,則在後面補0,補0轉換...
aes加解密之base64解碼遇到的坑
場景 從伺服器get請求獲取到資料之後,需要將資料進行aes解密。方法 1 get請求,獲取資料。2 base64解碼。報錯 illegal base64 data at input byte 0 想說應該是伺服器傳過來的資料報含了非法字元,但是列印到螢幕之後自動替換了非法字元。解決辦法 將獲取到的...