-
-
Save matheuseduardo/6d205904ec66cf4332c91cb539729ce4 to your computer and use it in GitHub Desktop.
<% | |
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 | |
%> |
I solved that problem via replacing Chr(10) and Chr(13) to empty.
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 = Replace(Replace(oNode.text, Chr(10), ""), Chr(13), "")
Set oNode = Nothing
Set oXML = Nothing
End Function
Thanks @matheuseduardo and @hakansglm for your time!
Korean characters are converted into somewhat unreadable strings.
Dim encode
encode = Base64Encode("{""device"":""pc"",""user"":{""id"":10,""level"":1,""login_id"":""lorem29"",""login_name"":""회원가입신청"",""language"":""en""}}")
It returns
{"device":"pc","user":{"id":10,"level":1,"login_id":"lorem29","login_name":"isOi>?e??iz.i< i2-","language":"en"}}
Any idea why and how to solve this?
Korean characters are converted into somewhat unreadable strings.
Dim encode encode = Base64Encode("{""device"":""pc"",""user"":{""id"":10,""level"":1,""login_id"":""lorem29"",""login_name"":""회원가입신청"",""language"":""en""}}")
It returns
{"device":"pc","user":{"id":10,"level":1,"login_id":"lorem29","login_name":"isOi>?e??iz.i< i2-","language":"en"}}
Any idea why and how to solve this?
I use the Base64 class:
https://gist.github.com/domus71/f593fcc2fec3d9a4eb68fdf2034bf11d
I solved that problem via replacing Chr(10) and Chr(13) to empty.
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)
End Function