Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- test()
- ExitApp()
- test(){
- ; SGVsbG8sIHdvcmxkIQ==
- txt := "Hello, world!"
- enc := base64_encode(txt)
- dec := base64_decode(enc)
- MsgBox "start: " txt
- . "`nencode: " enc
- . "`ndecode: " dec
- }
- base64_decode(strIn){
- static CRYPT_STRING_BASE64 := 0x1
- , encoding := "UTF-8"
- ; bufStr := Buffer(StrPut(strIn, encoding))
- ; StrPut(strIn, bufStr, encoding)
- strSize := StrPut(strIn, encoding)
- ; pcb := Buffer(4, 0)
- chars := 0
- if (!DllCall("Crypt32\CryptStringToBinary"
- ,"Str" , &strIn ;[in] LPCSTR pszString,
- ,"UInt" , strSize ;[in] DWORD cchString,
- ,"UInt" , CRYPT_STRING_BASE64 ;[in] DWORD dwFlags,
- ,"Ptr" , 0 ;[in] BYTE *pbBinary,
- ,"UInt*" , &chars ;[in, out] DWORD *pcbBinary,
- ,"Ptr" , 0 ;[out] DWORD *pdwSkip,
- ,"Ptr" , 0 )) ;[out] DWORD *pdwFlags
- MsgBox "Error getting decode size"
- strOut := ""
- VarSetStrCapacity(&strOut, chars)
- if (!DllCall("Crypt32\CryptStringToBinary"
- ,"Str" , &strIn ;[in] LPCSTR pszString,
- ,"UInt" , strSize ;[in] DWORD cchString,
- ,"UInt" , CRYPT_STRING_BASE64 ;[in] DWORD dwFlags,
- ,"Str" , &strOut ;[in] BYTE *pbBinary,
- ,"UInt*" , &chars ;[in, out] DWORD *pcbBinary,
- ,"Ptr" , 0 ;[out] DWORD *pdwSkip,
- ,"Ptr" , 0 )) ;[out] DWORD *pdwFlags
- MsgBox "Error getting decode string"
- return StrGet(StrPtr(strOut), encoding)
- }
- base64_encode(strIn) {
- static CRYPT_STRING_BASE64 := 0x1
- , encoding := "UTF-8"
- bufStr := Buffer(StrPut(strIn, encoding))
- StrPut(strIn, bufStr, encoding)
- chars := 0
- if !DllCall("Crypt32\CryptBinaryToString"
- ,"Ptr" ,bufStr ; const BYTE *pbBinary,
- ,"UInt" ,bufStr.Size ; DWORD cbBinary,
- ,"UInt" ,CRYPT_STRING_BASE64 ; DWORD dwFlags,
- ,"Ptr" ,0 ; LPWSTR pszString,
- ,"UInt*" ,&chars) ; DWORD *pcchString
- MsgBox("Error")
- VarSetStrCapacity(&strOut, chars)
- if !DllCall("Crypt32\CryptBinaryToString"
- ,"Ptr" ,bufStr ; const BYTE *pbBinary,
- ,"UInt" ,bufStr.Size ; DWORD cbBinary,
- ,"UInt" ,CRYPT_STRING_BASE64 ; DWORD dwFlags,
- ,"Str" ,strOut ; LPWSTR pszString,
- ,"UInt*" ,&chars ) ; DWORD *pcchString
- MsgBox("Error")
- return Trim(strOut, "`r`n")
- }
Add Comment
Please, Sign In to add comment