Jump to content
Sign in to follow this  
ogrish

AutoIT base64 encoding problem

Recommended Posts

ogrish

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

Share this post


Link to post
Share on other sites
JFX

:Unicode.GetBytes($commands) :mellow:

maybe you should you a Unicode string in your script too.

Share this post


Link to post
Share on other sites
jvanegmond

: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

Share this post


Link to post
Share on other sites
ogrish

:Unicode.GetBytes($commands) :mellow:

maybe you should you a Unicode string in your script too.

Thanks JFX. You solved my problem. I use Lazycats Asc2Unicode solved my problem.

Share this post


Link to post
Share on other sites
ogrish

Thanks Manadar :mellow:

Share this post


Link to post
Share on other sites
SmOke_N

Curious, does this work for you?


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
ogrish

Curious, does this work for you?

yes i tried, it works. Thanks!

Share this post


Link to post
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
Sign in to follow this  

×