Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Dim fso, MyFile
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set MyFile = fso.CreateTextFile("tmp.txt", True)
- Dim test
- test = base64Decode("VGVzdHBhc3N3b3J0")
- 'Wscript.StdOut.Write test
- MyFile.Write(test)
- MyFile.Close
- Function Base64Encode(sText)
- Dim oXML, oNode
- Set oXML = CreateObject("Msxml2.DOMDocument.3.0")
- Set oNode = oXML.CreateElement("base64")
- oNode.dataType = "bin.base64"
- oNode.nodeTypedValue =Stream_StringToBinary(sText)
- Base64Encode = oNode.text
- Set oNode = Nothing
- Set oXML = Nothing
- End Function
- Function Base64Decode(ByVal vCode)
- Dim oXML, oNode
- Set oXML = CreateObject("Msxml2.DOMDocument.3.0")
- Set oNode = oXML.CreateElement("base64")
- oNode.dataType = "bin.base64"
- oNode.text = vCode
- Base64Decode = Stream_BinaryToString(oNode.nodeTypedValue)
- Set oNode = Nothing
- Set oXML = Nothing
- End Function
- Function Stream_StringToBinary(Text)
- Const adTypeText = 2
- Const adTypeBinary = 1
- 'Create Stream object
- Dim BinaryStream 'As New Stream
- Set BinaryStream = CreateObject("ADODB.Stream")
- 'Specify stream type - we want To save text/string data.
- BinaryStream.Type = adTypeText
- 'Specify charset For the source text (unicode) data.
- BinaryStream.CharSet = "us-ascii"
- 'Open the stream And write text/string data To the object
- BinaryStream.Open
- BinaryStream.WriteText Text
- 'Change stream type To binary
- BinaryStream.Position = 0
- BinaryStream.Type = adTypeBinary
- 'Ignore first two bytes - sign of
- BinaryStream.Position = 0
- 'Open the stream And get binary data from the object
- Stream_StringToBinary = BinaryStream.Read
- Set BinaryStream = Nothing
- End Function
- Function Stream_BinaryToString(Binary)
- Const adTypeText = 2
- Const adTypeBinary = 1
- 'Create Stream object
- Dim BinaryStream 'As New Stream
- Set BinaryStream = CreateObject("ADODB.Stream")
- 'Specify stream type - we want To save text/string data.
- BinaryStream.Type = adTypeBinary
- 'Open the stream And write text/string data To the object
- BinaryStream.Open
- BinaryStream.Write Binary
- 'Change stream type To binary
- BinaryStream.Position = 0
- BinaryStream.Type = adTypeText
- 'Specify charset For the source text (unicode) data.
- If Len(CharSet) > 0 Then
- BinaryStream.CharSet = CharSet
- Else
- BinaryStream.CharSet = "us-ascii"
- End If
- 'Open the stream And get binary data from the object
- Stream_BinaryToString = BinaryStream.ReadText
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement