;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       Base64() 
;; 
;;ACTION         Performs Base64 Encode/Decode operations 
;; 
;;AUTHOR         Flavien 
;; 
;;CONTRIBUTORS   Allen 
;; 
;;VERSION        1.0 - 2011/10/08 
;; 
;;HISTORY        1.0 - 2011/10/08 - Initial Release 
;; 
;;SYNTAX         Base64(string[, mode]) 
;; 
;;PARAMETERS     string - REQUIRED - String to convert 
;; 
;;               mode   - OPTIONAL - set to TRUE to DECODE, default is ENCODE 
;; 
;;REMARKS         
;; 
;;RETURNS        String 
;; 
;;DEPENDENCIES   none 
;; 
;;TESTED WITH    W2K8, W2K12, W2K16 
;; 
;;EXAMPLES        
; 
Function Base64($_String, Optional $_Mode)
 
  Dim $_xml_object, $_xml_doc, $_stream_object, $_strXML
  Dim $_X
  Dim $_RC
 
  $_xml_object = CreateObject('MSXML2.DOMDocument.3.0')
 
  If $_Mode
    $_strXML='<B64DECODE xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="bin.base64">' + $_String + '</B64DECODE>'
    $_RC = $_XML_object.LoadXML($_strXML)
    $Base64 = $_XML_object.selectsinglenode("B64DECODE").nodeTypedValue
  Else
    $_stream_object = createobject("ADODB.Stream")
    $_stream_object.type = 2
    $_stream_object.charset = "us-ascii"
    $_X = $_stream_object.open
    $_X = $_stream_object.writetext($_string)
    $_stream_object.position = 0
    $_stream_object.type = 1
    $_stream_object.position = 0
    $_string = $_stream_object.read
    $_xml_doc = $_xml_object.createelement("base64")
    $_xml_doc.datatype = "bin.base64"
    $_xml_doc.nodetypedvalue = $_string
 
    $Base64 = $_xml_doc.text
 
    $_stream_object = ""
    $_xml_doc = ""
    $_xml_object = ""
  EndIf
 
EndFunction