Before Encryption: 1234567890
Encrypted: MTIzNDU2Nzg5MA
After decryption: 1234567890
Source code:
<%
OPTION EXPLICIT
Const BASE_64_MAP_INIT = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 + /"
Dim newline
Dim Base64EncMap (63)
Dim Base64DecMap (127)
'Initialization function
Public sub initCodecs ()
'Initialization variable
Newline = "<P>" & 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 encryption function
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 (first * 16) AND 48)
Ret = ret '& "="
End if
Ret = ret '& "="
End if
Base64Encode = ret
END FUNCTION
'Base64 decryption function
Public function base64Decode (scrambled)
If len (scrambled) = 0 then
Base64Decode = ""
Exit function
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.