GroggyOtter

b64 enc/dec working

Feb 2nd, 2023
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. test()
  2. ExitApp()
  3.  
  4. test(){
  5. ; SGVsbG8sIHdvcmxkIQ==
  6. txt := "Hello, world!"
  7. enc := base64_encode(txt)
  8. dec := base64_decode(enc)
  9. MsgBox "start: " txt
  10. . "`nencode: " enc
  11. . "`ndecode: " dec
  12. }
  13.  
  14.  
  15. base64_decode(strIn){
  16. static CRYPT_STRING_BASE64 := 0x1
  17. , encoding := "UTF-8"
  18.  
  19. ; bufStr := Buffer(StrPut(strIn, encoding))
  20. ; StrPut(strIn, bufStr, encoding)
  21. strSize := StrPut(strIn, encoding)
  22.  
  23. ; pcb := Buffer(4, 0)
  24. chars := 0
  25.  
  26. if (!DllCall("Crypt32\CryptStringToBinary"
  27. ,"Str" , &strIn ;[in] LPCSTR pszString,
  28. ,"UInt" , strSize ;[in] DWORD cchString,
  29. ,"UInt" , CRYPT_STRING_BASE64 ;[in] DWORD dwFlags,
  30. ,"Ptr" , 0 ;[in] BYTE *pbBinary,
  31. ,"UInt*" , &chars ;[in, out] DWORD *pcbBinary,
  32. ,"Ptr" , 0 ;[out] DWORD *pdwSkip,
  33. ,"Ptr" , 0 )) ;[out] DWORD *pdwFlags
  34. MsgBox "Error getting decode size"
  35.  
  36. strOut := ""
  37. VarSetStrCapacity(&strOut, chars)
  38.  
  39. if (!DllCall("Crypt32\CryptStringToBinary"
  40. ,"Str" , &strIn ;[in] LPCSTR pszString,
  41. ,"UInt" , strSize ;[in] DWORD cchString,
  42. ,"UInt" , CRYPT_STRING_BASE64 ;[in] DWORD dwFlags,
  43. ,"Str" , &strOut ;[in] BYTE *pbBinary,
  44. ,"UInt*" , &chars ;[in, out] DWORD *pcbBinary,
  45. ,"Ptr" , 0 ;[out] DWORD *pdwSkip,
  46. ,"Ptr" , 0 )) ;[out] DWORD *pdwFlags
  47. MsgBox "Error getting decode string"
  48.  
  49. return StrGet(StrPtr(strOut), encoding)
  50. }
  51.  
  52. base64_encode(strIn) {
  53. static CRYPT_STRING_BASE64 := 0x1
  54. , encoding := "UTF-8"
  55.  
  56. bufStr := Buffer(StrPut(strIn, encoding))
  57. StrPut(strIn, bufStr, encoding)
  58. chars := 0
  59.  
  60. if !DllCall("Crypt32\CryptBinaryToString"
  61. ,"Ptr" ,bufStr ; const BYTE *pbBinary,
  62. ,"UInt" ,bufStr.Size ; DWORD cbBinary,
  63. ,"UInt" ,CRYPT_STRING_BASE64 ; DWORD dwFlags,
  64. ,"Ptr" ,0 ; LPWSTR pszString,
  65. ,"UInt*" ,&chars) ; DWORD *pcchString
  66. MsgBox("Error")
  67.  
  68. VarSetStrCapacity(&strOut, chars)
  69.  
  70. if !DllCall("Crypt32\CryptBinaryToString"
  71. ,"Ptr" ,bufStr ; const BYTE *pbBinary,
  72. ,"UInt" ,bufStr.Size ; DWORD cbBinary,
  73. ,"UInt" ,CRYPT_STRING_BASE64 ; DWORD dwFlags,
  74. ,"Str" ,strOut ; LPWSTR pszString,
  75. ,"UInt*" ,&chars ) ; DWORD *pcchString
  76. MsgBox("Error")
  77. return Trim(strOut, "`r`n")
  78. }
  79.  
Add Comment
Please, Sign In to add comment