Advertisement
Guest User

Snowman25

a guest
Oct 28th, 2009
2,719
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. Dim fso, MyFile
  2. Set fso = CreateObject("Scripting.FileSystemObject")
  3. Set MyFile = fso.CreateTextFile("tmp.txt", True)
  4. Dim test
  5. test = base64Decode("VGVzdHBhc3N3b3J0")
  6. 'Wscript.StdOut.Write test
  7. MyFile.Write(test)
  8. MyFile.Close
  9.  
  10. Function Base64Encode(sText)
  11. Dim oXML, oNode
  12. Set oXML = CreateObject("Msxml2.DOMDocument.3.0")
  13. Set oNode = oXML.CreateElement("base64")
  14. oNode.dataType = "bin.base64"
  15. oNode.nodeTypedValue =Stream_StringToBinary(sText)
  16. Base64Encode = oNode.text
  17. Set oNode = Nothing
  18. Set oXML = Nothing
  19. End Function
  20. Function Base64Decode(ByVal vCode)
  21. Dim oXML, oNode
  22.  
  23. Set oXML = CreateObject("Msxml2.DOMDocument.3.0")
  24. Set oNode = oXML.CreateElement("base64")
  25. oNode.dataType = "bin.base64"
  26. oNode.text = vCode
  27. Base64Decode = Stream_BinaryToString(oNode.nodeTypedValue)
  28. Set oNode = Nothing
  29. Set oXML = Nothing
  30. End Function
  31. Function Stream_StringToBinary(Text)
  32. Const adTypeText = 2
  33. Const adTypeBinary = 1
  34.  
  35. 'Create Stream object
  36. Dim BinaryStream 'As New Stream
  37. Set BinaryStream = CreateObject("ADODB.Stream")
  38.  
  39. 'Specify stream type - we want To save text/string data.
  40. BinaryStream.Type = adTypeText
  41.  
  42. 'Specify charset For the source text (unicode) data.
  43. BinaryStream.CharSet = "us-ascii"
  44.  
  45. 'Open the stream And write text/string data To the object
  46. BinaryStream.Open
  47. BinaryStream.WriteText Text
  48.  
  49. 'Change stream type To binary
  50. BinaryStream.Position = 0
  51. BinaryStream.Type = adTypeBinary
  52.  
  53. 'Ignore first two bytes - sign of
  54. BinaryStream.Position = 0
  55.  
  56. 'Open the stream And get binary data from the object
  57. Stream_StringToBinary = BinaryStream.Read
  58.  
  59. Set BinaryStream = Nothing
  60. End Function
  61. Function Stream_BinaryToString(Binary)
  62. Const adTypeText = 2
  63. Const adTypeBinary = 1
  64.  
  65. 'Create Stream object
  66. Dim BinaryStream 'As New Stream
  67. Set BinaryStream = CreateObject("ADODB.Stream")
  68.  
  69. 'Specify stream type - we want To save text/string data.
  70. BinaryStream.Type = adTypeBinary
  71.  
  72. 'Open the stream And write text/string data To the object
  73. BinaryStream.Open
  74. BinaryStream.Write Binary
  75.  
  76.  
  77. 'Change stream type To binary
  78. BinaryStream.Position = 0
  79. BinaryStream.Type = adTypeText
  80.  
  81. 'Specify charset For the source text (unicode) data.
  82. If Len(CharSet) > 0 Then
  83. BinaryStream.CharSet = CharSet
  84. Else
  85. BinaryStream.CharSet = "us-ascii"
  86. End If
  87.  
  88. 'Open the stream And get binary data from the object
  89. Stream_BinaryToString = BinaryStream.ReadText
  90. End Function
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement