!!! Out of support for the time being !!!
Just a Class version of SKAN's Base64enc() / Base64dec() - Base64 encoder / decoder, tested with AHK U64 also.
Note: You may safely use the ANSI version of CryptBinaryToString
with Unicode builds and save a lot of space.
Class_Base64.ahk:
; ====================================================================================================================== ; Namespace: Base64 ; AHK version: AHK 1.1.+ (required) ; Function: Methods for Base64 en/decoding. ; Language: English ; Tested on: Win XPSP3, Win VistaSP2 (U32) / Win 7 (U64) ; Version: 1.0.00.00/2012-08-12/just me ; URL: http://msdn.microsoft.com/en-us/library/windows/desktop/aa380252(v=vs.85).aspx ; Remarks: The ANSI functions are used by default to save space. ANSI needs about 133 % of the original size for ; encoding, whereas Unicode needs about 266 %. ; ====================================================================================================================== ; This software is provided 'as-is', without any express or implied warranty. ; In no event will the authors be held liable for any damages arising from the use of this software. ; ====================================================================================================================== Class Base64 { ; CRYPT_STRING_BASE64 = 0x01 ; =================================================================================================================== ; Base64.Encode() ; Parameters: ; VarIn - Variable containing the input buffer ; SizeIn - Size of the input buffer in bytes ; VarOut - Variable to receive the encoded buffer ; Use - Use ANSI (A) or Unicode (W) function ; Default: A ; Return values: ; On success: Number of bytes copied to VarOut, not including the terminating null character ; On failure: False ; Remarks: ; VarIn may contain any binary contents including NUll bytes. ; =================================================================================================================== Encode(ByRef VarIn, SizeIn, ByRef VarOut, Use = "A") { Static Codec := 0x01 ; CRYPT_STRING_BASE64 If (Use <> "W") Use := "A" Enc := "Crypt32.dll\CryptBinaryToString" . Use If !DllCall(Enc, "Ptr", &VarIn, "UInt", SizeIn, "UInt", Codec, "Ptr", 0, "UIntP", SizeOut) Return False VarSetCapacity(VarOut, SizeOut << (Use = "W"), 0) If !DllCall(Enc, "Ptr", &VarIn, "UInt", SizeIn, "UInt", Codec, "Ptr", &VarOut, "UIntP", SizeOut) Return False Return SizeOut << (Use = "W") } ; =================================================================================================================== ; Base64.Decode() ; Parameters: ; VarIn - Variable containing a null-terminated Base64 encoded string ; VarOut - Variable to receive the decoded buffer ; Use - Use ANSI (A) or Unicode (W) function ; Default: A ; Return values: ; On success: Number of bytes copied to VarOut ; On failure: False ; Remarks: ; VarOut may contain any binary contents including NUll bytes. ; =================================================================================================================== Decode(ByRef VarIn, ByRef VarOut, Use = "A") { Static Codec := 0x01 ; CRYPT_STRING_BASE64 If (Use <> "W") Use := "A" Dec := "Crypt32.dll\CryptStringToBinary" . Use If !DllCall(Dec, "Ptr", &VarIn, "UInt", 0, "UInt", Codec, "Ptr", 0, "UIntP", SizeOut, "Ptr", 0, "Ptr", 0) Return False VarSetCapacity(VarOut, SizeOut, 0) If !DllCall(Dec, "Ptr", &VarIn, "UInt", 0, "UInt", Codec, "Ptr", &VarOut, "UIntP", SizeOut, "Ptr", 0, "Ptr", 0) Return False Return SizeOut } }
Sample.ahk:
#NoEnv #Include Class_Base64.ahk String := "Lorem ipsum dolor sit amet consectetuer pede eros tortor Vestibulum Aliquam. Id eget orci sed lobortis " . "felis urna Donec suscipit nibh id. Tellus semper Nulla pretium et nibh diam venenatis wisi cursus " . "adipiscing. Hendrerit lacinia ut laoreet quis a cursus Sed justo Nunc In. Tincidunt accumsan hac hac id " . "non eleifend Vivamus Fusce risus ac. Elit nec nec." Bytes := StrLen(String) << !!A_IsUnicode Encoded := Decoded := "" If !(SizeE := Base64.Encode(String, Bytes, Encoded, "A")) Encoded := "Base64.Encode failed!" Else If !(SizeD := Base64.Decode(Encoded, Decoded, "A")) Decoded := "Base64.Decode failed!" Gui, Margin, 20, 20 Gui, Font, s9, Courier New Gui, Add, Text, xm cNavy, Original (Size = %Bytes% bytes) Gui, Add, Text, xm y+5 w800, %String% Gui, Add, Text, xm cNavy, Encoded (Size = %SizeE% bytes) Gui, Add, Text, xm y+5 w800, %Encoded% Gui, Add, Text, xm cNavy, Decoded (Size = %SizeD% bytes) Gui, Add, Text, xm y+5 w800, Þcoded% Gui, Show, , Class Base64 Sample Return GuiClose: GuiEscape: ExitApp