<%
Function Base64Encode(sString)
If sString = "" Or IsNull(sString) Then
Base64Encode = ""
Exit Function
End if
Dim xml_dom, Node
Set xml_dom = Server.CreateObject("Microsoft.XMLDOM")
With xml_dom
.async = False
.loadXML "<?xml version='1.0' ?><root />"
Set Node = xml_dom.createElement("MyText")
With Node
.dataType = "bin.base64"
.nodeTypedValue = Stream_StringToBinary(sString)
NodeText = Node.text
NodeText = Trim(NodeText)
NodeText=Replace(NodeText,vbcrlf,"")
NodeText=Replace(NodeText,vbtab,"")
If InStr(NodeText, Chr(10)) > 0 Then
NodeText=Replace(NodeText,Chr(10),"")
End If
Base64Encode = NodeText
End With
xml_dom.documentElement.appendChild Node
End With
set xml_dom = Nothing
End Function
function Stream_StringToBinary(sString)
Dim Stream, BinaryStream
Set Stream = Server.CreateObject("ADODB.Stream")
Stream.Type = 2
Stream.Charset = "utf-8"
Stream.Open
Stream.WriteText sString
Stream.Position = 0
Stream.Type = 1
Stream.Position = 0
Stream_StringToBinary = Stream.Read
Stream.Close
Set Stream = Nothing
End Function
Function Base64Decode(sString)
If sString = "" Or IsNull(sString) Then
Base64Decode = ""
Exit Function
End if
Dim xml_dom, Node
Set xml_dom = Server.CreateObject("Microsoft.XMLDOM")
With xml_dom
.async = False
.loadXML "<?xml version='1.0' ?><root />"
Set Node = xml_dom.createElement("MyText")
With Node
.dataType = "bin.base64"
.text = Trim(sString)
Base64Decode = Stream_BinaryToString(.nodeTypedValue)
End With
xml_dom.documentElement.appendChild Node
End With
set xml_dom = Nothing
End Function
function Stream_BinaryToString(Binary)
Dim Stream
Set Stream = Server.CreateObject("ADODB.Stream")
Stream.Type = 1
Stream.Open
Stream.Write Binary
Stream.Position = 0
Stream.Type = 2
Stream.Charset = "utf-8"
Stream_BinaryToString = Stream.ReadText
Stream.Close
Set Stream = Nothing
End Function
%>
Base64 Encode
asp+base64