Jump to content

AutoIT base64 encoding problem


 Share

Recommended Posts

Hi guys,

I use to get base64 encoding of a string. The code is as follows:

#Include "Base64.au3"

Dim $Encode = _Base64Encode("ps")
MsgBox(0, 'Base64 Encode Data', $Encode)

When running it, I got the result:

cHM=

Then I use the following PowerShell code to get the the base64 encoding of the same string "ps":

$commands = 'ps'
$bytes = [System.Text.Encoding]::Unicode.GetBytes($commands)
$encodedString = [Convert]::ToBase64String($bytes)
$encodedString

What I got is:

cABzAA==

Infact the result from PowerShell is what I want. I want to know how to get the same result using AutoIt? I guess this is a character encoding issue, not sure.

Thanks.

Edited by ogrish
Link to comment
Share on other sites

:mellow: http://stackoverflow.com/questions/7064776/how-can-i-get-the-same-base64-encoding-result-from-autoit-as-what-from-powershell

#Include "Base64.au3"

Dim $Encode = _Base64WEncode("ps")
ConsoleWrite($Encode & @CRLF)

Func _Base64WEncode($string)
    Local $result = ""
    Local $arr = StringSplit($string, "")
    For $i = 1 To UBound($arr) - 1
        $result &= $arr[$i] & Chr(0)
    Next
    $result = _Base64Encode($result)
    Return $result
EndFunc
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...