Created
July 12, 2018 18:50
-
-
Save matheuseduardo/6d205904ec66cf4332c91cb539729ce4 to your computer and use it in GitHub Desktop.
Base64 encoding / decoding functions in VbScript / Classic ASP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
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 | |
Private Function Stream_StringToBinary(Text) | |
Const adTypeText = 2 | |
Const adTypeBinary = 1 | |
Dim BinaryStream 'As New Stream | |
Set BinaryStream = CreateObject("ADODB.Stream") | |
BinaryStream.Type = adTypeText | |
BinaryStream.CharSet = "us-ascii" | |
BinaryStream.Open | |
BinaryStream.WriteText Text | |
BinaryStream.Position = 0 | |
BinaryStream.Type = adTypeBinary | |
BinaryStream.Position = 0 | |
Stream_StringToBinary = BinaryStream.Read | |
Set BinaryStream = Nothing | |
End Function | |
Private Function Stream_BinaryToString(Binary) | |
Const adTypeText = 2 | |
Const adTypeBinary = 1 | |
Dim BinaryStream 'As New Stream | |
Set BinaryStream = CreateObject("ADODB.Stream") | |
BinaryStream.Type = adTypeBinary | |
BinaryStream.Open | |
BinaryStream.Write Binary | |
BinaryStream.Position = 0 | |
BinaryStream.Type = adTypeText | |
BinaryStream.CharSet = "us-ascii" | |
Stream_BinaryToString = BinaryStream.ReadText | |
Set BinaryStream = Nothing | |
End Function | |
%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@KarmaBlackshaw
I use the Base64 class:
https://gist.github.com/domus71/f593fcc2fec3d9a4eb68fdf2034bf11d