Ascer Posted February 11, 2018 Share Posted February 11, 2018 (edited) Hello. A couple week ago i've started learning API Interface for different websites. In this fact sometimes you have to encode your "photo" or "document.body" to send request. Functions to encode and decode Base64 was already created by others. Unfortunately i have troubles with running it on Windows R 2008, also speed was terrible. I try to find alternative way to code data. I've read about Microsoft "XMLDOM" and created a one simple function to Encode / Decode data to base64binary, base64url Thanks for Ghads on Wordpress i coverted a part of his lines from VBscript to AutoIT ;============================================================================================================================== ; Function: base64($vCode [, $bEncode = True [, $bUrl = False]]) ; ; Description: Decode or Encode $vData using Microsoft.XMLDOM to Base64Binary or Base64Url. ; IMPORTANT! Encoded base64url is without @LF after 72 lines. Some websites may require this. ; ; Parameter(s): $vData - string or integer | Data to encode or decode. ; $bEncode - boolean | True - encode, False - decode. ; $bUrl - boolean | True - output is will decoded or encoded using base64url shema. ; ; Return Value(s): On Success - Returns output data ; On Failure - Returns 1 - Failed to create object. ; ; Author (s): (Ghads on Wordpress.com), Ascer ;=============================================================================================================================== Func base64($vCode, $bEncode = True, $bUrl = False) Local $oDM = ObjCreate("Microsoft.XMLDOM") If Not IsObj($oDM) Then Return SetError(1, 0, 1) Local $oEL = $oDM.createElement("Tmp") $oEL.DataType = "bin.base64" If $bEncode then $oEL.NodeTypedValue = Binary($vCode) If Not $bUrl Then Return $oEL.Text Return StringReplace(StringReplace(StringReplace($oEL.Text, "+", "-"),"/", "_"), @LF, "") Else If $bUrl Then $vCode = StringReplace(StringReplace($vCode, "-", "+"), "_", "/") $oEL.Text = $vCode Return $oEL.NodeTypedValue EndIf EndFunc ;==>base64 Edited February 12, 2018 by Ascer coffeeturtle and Zohar 2 Link to comment Share on other sites More sharing options...
jcpetu Posted February 18, 2018 Share Posted February 18, 2018 Hi Ascer, any example to understand how to use it. thanks in advance and regards. Link to comment Share on other sites More sharing options...
Ascer Posted February 18, 2018 Author Share Posted February 18, 2018 Here you are. Local $vData = "Hello jcpetu this is an example using base64 func.khsfishfiagsfgiy9047019tcDV:{:J{B:CSgAAFCACXC>N<@#$%#$^@@#%@#$^TCCCCCKGAS GZG" print("Your data for this example is [" & $vData & "]" & @CRLF) print("1. Method: String -> Base64Binary") Local $sBase64Binary = base64($vData) print("Output: " & $sBase64Binary & @CRLF) print("2. Method: Base64Binary -> String") print("Output: " & BinaryToString(base64($sBase64Binary, False)) & @CRLF) ; used binary to string because base64 func first convert data to Binary (some web dont do this) print("3. Method: String -> Base64Url") Local $sBase64Url = base64($vData, True, True) print("Output: " & $sBase64Url & @CRLF) print("4. Method: Base64Url -> String") print("Output: " & BinaryToString(base64($sBase64Url, False, True)) & @CRLF) Func print($vData) Return ConsoleWrite($vData & @CRLF) EndFunc ;==>print() coffeeturtle 1 Link to comment Share on other sites More sharing options...
jcpetu Posted February 18, 2018 Share Posted February 18, 2018 Thanks a lot Ascer. Link to comment Share on other sites More sharing options...
Zohar Posted April 29, 2018 Share Posted April 29, 2018 Thank you Ascer, that was really useful.. BTW do we need to release the XMLDOM object? (what is AutoIt's behavior for such objects, if not released bty the developer?) Link to comment Share on other sites More sharing options...
mLipok Posted April 29, 2018 Share Posted April 29, 2018 21 minutes ago, Zohar said: BTW do we need to release the XMLDOM object? (what is AutoIt's behavior for such objects, if not released bty the developer?) As far as I know this is released in MS Windows in each version which is currently supported by AutoIt. Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
Zohar Posted May 1, 2018 Share Posted May 1, 2018 Hmm Imagine this object being created 20-30 times per minute, without being explicitly released by the developer.. I think it would be good to release it. Link to comment Share on other sites More sharing options...
mLipok Posted May 1, 2018 Share Posted May 1, 2018 ah ... you mean cleanup, not distribuate ... I apologize for my mistake. AutoIt should destroy each local variable when you exit function, but this is good practices to CleanUp object by assigning value to variable , but in this case object is used in Return line so it would be "difficult" . Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
Radix Posted December 26, 2019 Share Posted December 26, 2019 On 2/18/2018 at 3:04 PM, Ascer said: Here you are. Local $vData = "Hello jcpetu this is an example using base64 func.khsfishfiagsfgiy9047019tcDV:{:J{B:CSgAAFCACXC>N<@#$%#$^@@#%@#$^TCCCCCKGAS GZG" print("Your data for this example is [" & $vData & "]" & @CRLF) print("1. Method: String -> Base64Binary") Local $sBase64Binary = base64($vData) print("Output: " & $sBase64Binary & @CRLF) print("2. Method: Base64Binary -> String") print("Output: " & BinaryToString(base64($sBase64Binary, False)) & @CRLF) ; used binary to string because base64 func first convert data to Binary (some web dont do this) print("3. Method: String -> Base64Url") Local $sBase64Url = base64($vData, True, True) print("Output: " & $sBase64Url & @CRLF) print("4. Method: Base64Url -> String") print("Output: " & BinaryToString(base64($sBase64Url, False, True)) & @CRLF) Func print($vData) Return ConsoleWrite($vData & @CRLF) EndFunc ;==>print() Error: The request action with this object failed... Link to comment Share on other sites More sharing options...
Musashi Posted December 26, 2019 Share Posted December 26, 2019 (edited) 6 hours ago, Radix said: Error: The request action with this object failed... Could you please provide details about your system : OS, AutoIt-Version, etc. For me, this works : expandcollapse popup#cs ---------------------------------------------------------------------------- Source : https://www.autoitscript.com/forum/topic/192404-base64-autoit-encode-decode-extra-fast/?do=findComment&comment=1380831 -> Uses Microsofts "XMLDOM" and created a one simple function to Encode / Decode data to base64binary, base64url #ce ---------------------------------------------------------------------------- ; ----------------------------------------------------------------------------------------- ; Example : ; ----------------------------------------------------------------------------------------- Local $vData = "Hello jcpetu this is an example using base64 func.khsfishfiagsfgiy9047019tcDV:{:J{B:CSgAAFCACXC>N<@#$%#$^@@#%@#$^TCCCCCKGAS GZG" print("Your data for this example is [" & $vData & "]" & @CRLF) print("1. Method: String -> Base64Binary") Local $sBase64Binary = base64($vData) print("Output: " & $sBase64Binary & @CRLF) print("2. Method: Base64Binary -> String") print("Output: " & BinaryToString(base64($sBase64Binary, False)) & @CRLF) ; used binary to string because base64 func first convert data to Binary (some web dont do this) print("3. Method: String -> Base64Url") Local $sBase64Url = base64($vData, True, True) print("Output: " & $sBase64Url & @CRLF) print("4. Method: Base64Url -> String") print("Output: " & BinaryToString(base64($sBase64Url, False, True)) & @CRLF) Func print($vData) Return ConsoleWrite($vData & @CRLF) EndFunc ;==>print() ; ----------------------------------------------------------------------------------------- ;============================================================================================================================== ; Function: base64($vCode [, $bEncode = True [, $bUrl = False]]) ; ; Description: Decode or Encode $vData using Microsoft.XMLDOM to Base64Binary or Base64Url. ; IMPORTANT! Encoded base64url is without @LF after 72 lines. Some websites may require this. ; ; Parameter(s): $vData - string or integer | Data to encode or decode. ; $bEncode - boolean | True - encode, False - decode. ; $bUrl - boolean | True - output is will decoded or encoded using base64url shema. ; ; Return Value(s): On Success - Returns output data ; On Failure - Returns 1 - Failed to create object. ; ; Author (s): (Ghads on Wordpress.com), Ascer ;=============================================================================================================================== Func base64($vCode, $bEncode = True, $bUrl = False) Local $oDM = ObjCreate("Microsoft.XMLDOM") If Not IsObj($oDM) Then Return SetError(1, 0, 1) Local $oEL = $oDM.createElement("Tmp") $oEL.DataType = "bin.base64" If $bEncode then $oEL.NodeTypedValue = Binary($vCode) If Not $bUrl Then Return $oEL.Text Return StringReplace(StringReplace(StringReplace($oEL.Text, "+", "-"),"/", "_"), @LF, "") Else If $bUrl Then $vCode = StringReplace(StringReplace($vCode, "-", "+"), "_", "/") $oEL.Text = $vCode Return $oEL.NodeTypedValue EndIf EndFunc ;==>base64 Edit @Radix : Also have a look at this script from @trancexx : _base64encode-_base64decode Spoiler expandcollapse popup$encoded = _Base64Encode("Testing") MsgBox(0, 'Base64 Encoded', $encoded) $decoded = _Base64Decode($encoded) MsgBox(0, 'Base64 Decoded - binary', $decoded) MsgBox(0, 'Base64 Decoded - string', BinaryToString($decoded)) Func _Base64Encode($input) $input = Binary($input) Local $struct = DllStructCreate("byte[" & BinaryLen($input) & "]") DllStructSetData($struct, 1, $input) Local $strc = DllStructCreate("int") Local $a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _ "ptr", DllStructGetPtr($struct), _ "int", DllStructGetSize($struct), _ "int", 1, _ "ptr", 0, _ "ptr", DllStructGetPtr($strc)) If @error Or Not $a_Call[0] Then Return SetError(1, 0, "") ; error calculating the length of the buffer needed EndIf Local $a = DllStructCreate("char[" & DllStructGetData($strc, 1) & "]") $a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _ "ptr", DllStructGetPtr($struct), _ "int", DllStructGetSize($struct), _ "int", 1, _ "ptr", DllStructGetPtr($a), _ "ptr", DllStructGetPtr($strc)) If @error Or Not $a_Call[0] Then Return SetError(2, 0, ""); error encoding EndIf Return DllStructGetData($a, 1) EndFunc ;==>_Base64Encode Func _Base64Decode($input_string) Local $struct = DllStructCreate("int") $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _ "str", $input_string, _ "int", 0, _ "int", 1, _ "ptr", 0, _ "ptr", DllStructGetPtr($struct, 1), _ "ptr", 0, _ "ptr", 0) If @error Or Not $a_Call[0] Then Return SetError(1, 0, "") ; error calculating the length of the buffer needed EndIf Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]") $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _ "str", $input_string, _ "int", 0, _ "int", 1, _ "ptr", DllStructGetPtr($a), _ "ptr", DllStructGetPtr($struct, 1), _ "ptr", 0, _ "ptr", 0) If @error Or Not $a_Call[0] Then Return SetError(2, 0, ""); error decoding EndIf Return DllStructGetData($a, 1) EndFunc ;==>_Base64Decode Edited December 26, 2019 by Musashi added second script "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Musashi Posted December 26, 2019 Share Posted December 26, 2019 Addition : I have written a small test script for people who are interested to compare the versions of @trancexx and @Ascer . You can 'play around' with it and make your own decision . expandcollapse popup#include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <StringConstants.au3> Opt("MustDeclareVars", 1) Global $g_sEncoded, $g_sDecoded, $g_sString, $g_iTime ; Bigtext : Global $g_sString = BinaryToString(InetRead("https://www.autoitscript.com/forum/"), 4) ;~ Global $g_sString = "Hello World, öäü ÖÄÜ ß" ; for simple tests ConsoleWrite(@CRLF) ConsoleWrite("+ >> StringLen = " & StringLen($g_sString) & @CRLF) ; ----------- Trancexx : --------------- ConsoleWrite(@CRLF) ConsoleWrite("+ >>>>> Trancexx <<<<< :" & @CRLF) ; Encode : $g_iTime = TimerInit() $g_sEncoded = _Base64Encode($g_sString) $g_iTime = TimerDiff($g_iTime) ConsoleWrite(StringFormat("% 25s: %10.3f ms", "Trancexx Encoding Time", $g_iTime)) ConsoleWrite(@CRLF) ; Decode : $g_iTime = TimerInit() $g_sDecoded = _Base64Decode($g_sEncoded) $g_iTime = TimerDiff($g_iTime) ConsoleWrite(StringFormat("% 25s: %10.3f ms", "Trancexx Decoding Time", $g_iTime)) ConsoleWrite(@CRLF) ; !!! don't use this for long strings - better write to file : ConsoleWrite($g_sEncoded & @CRLF) ConsoleWrite(BinaryToString($g_sDecoded) & @CRLF) ; ----------- Ascer : --------------- ConsoleWrite(@CRLF) ConsoleWrite("+ >>>>> Ascer <<<<< :" & @CRLF) ; Encode : $g_iTime = TimerInit() $g_sEncoded = base64($g_sString) $g_iTime = TimerDiff($g_iTime) ConsoleWrite(StringFormat("% 25s: %10.3f ms", "Ascer Encoding Time ", $g_iTime)) ConsoleWrite(@CRLF) ; Decode : $g_iTime = TimerInit() $g_sDecoded = base64($g_sEncoded, False) $g_iTime = TimerDiff($g_iTime) ConsoleWrite(StringFormat("% 25s: %10.3f ms", "Ascer Decoding Time ", $g_iTime)) ConsoleWrite(@CRLF) ; !!! don't use this for long strings - better write to file : ConsoleWrite($g_sEncoded & @CRLF) ConsoleWrite(BinaryToString($g_sDecoded) & @CRLF) ; ======================= Functions : ========================= ;--------------------------------------------------------------------------------- ; Trancexx : Func _Base64Encode($input) $input = Binary($input) Local $struct = DllStructCreate("byte[" & BinaryLen($input) & "]") DllStructSetData($struct, 1, $input) Local $strc = DllStructCreate("int") Local $a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _ "ptr", DllStructGetPtr($struct), _ "int", DllStructGetSize($struct), _ "int", 1, _ "ptr", 0, _ "ptr", DllStructGetPtr($strc)) If @error Or Not $a_Call[0] Then Return SetError(1, 0, "") ; error calculating the length of the buffer needed EndIf Local $a = DllStructCreate("char[" & DllStructGetData($strc, 1) & "]") $a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _ "ptr", DllStructGetPtr($struct), _ "int", DllStructGetSize($struct), _ "int", 1, _ "ptr", DllStructGetPtr($a), _ "ptr", DllStructGetPtr($strc)) If @error Or Not $a_Call[0] Then Return SetError(2, 0, ""); error encoding EndIf Return DllStructGetData($a, 1) EndFunc ;==>_Base64Encode Func _Base64Decode($input_string) Local $struct = DllStructCreate("int") Local $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _ "str", $input_string, _ "int", 0, _ "int", 1, _ "ptr", 0, _ "ptr", DllStructGetPtr($struct, 1), _ "ptr", 0, _ "ptr", 0) If @error Or Not $a_Call[0] Then Return SetError(1, 0, "") ; error calculating the length of the buffer needed EndIf Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]") $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _ "str", $input_string, _ "int", 0, _ "int", 1, _ "ptr", DllStructGetPtr($a), _ "ptr", DllStructGetPtr($struct, 1), _ "ptr", 0, _ "ptr", 0) If @error Or Not $a_Call[0] Then Return SetError(2, 0, ""); error decoding EndIf Return DllStructGetData($a, 1) EndFunc ;==>_Base64Decode ;--------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------- ; Ascer ;============================================================================================================================== ; Function: base64($vCode [, $bEncode = True [, $bUrl = False]]) ; ; Description: Decode or Encode $vData using Microsoft.XMLDOM to Base64Binary or Base64Url. ; IMPORTANT! Encoded base64url is without @LF after 72 lines. Some websites may require this. ; ; Parameter(s): $vData - string or integer | Data to encode or decode. ; $bEncode - boolean | True - encode, False - decode. ; $bUrl - boolean | True - output is will decoded or encoded using base64url shema. ; ; Return Value(s): On Success - Returns output data ; On Failure - Returns 1 - Failed to create object. ; ; Author (s): (Ghads on Wordpress.com), Ascer ;=============================================================================================================================== Func base64($vCode, $bEncode = True, $bUrl = False) Local $oDM = ObjCreate("Microsoft.XMLDOM") If Not IsObj($oDM) Then Return SetError(1, 0, 1) Local $oEL = $oDM.createElement("Tmp") $oEL.DataType = "bin.base64" If $bEncode then $oEL.NodeTypedValue = Binary($vCode) If Not $bUrl Then Return $oEL.Text Return StringReplace(StringReplace(StringReplace($oEL.Text, "+", "-"),"/", "_"), @LF, "") Else If $bUrl Then $vCode = StringReplace(StringReplace($vCode, "-", "+"), "_", "/") $oEL.Text = $vCode Return $oEL.NodeTypedValue EndIf EndFunc ;==>base64 ;--------------------------------------------------------------------------------- My result : The version from trancexx is faster. With extremely long strings, the version from Ascer caused an error message during decoding (on my system). Danp2, argumentum and NassauSky 2 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now