Jump to content

openssl encryption with autoit


Recommended Posts

Hi I'm trying to replicate a php function that I need:
 

function cripta($data){
    return openssl_encrypt($data,'AES-128-CBC',base64_decode("dGVzdHBhc3N3b3JkLi4uLg=="),0,"0102030405060708");
}

which is basically a base64encode of an aes encryption. I found some helpful UDF here which has both BASE64.au3 and AES.au3
I tried to write the "cripta" function:
 

#Include "AES.au3"
#include "BASE64.au3"

Global $mainKey = "dGVzdHBhc3N3b3JkLi4uLg=="
Global $mainIV = "0102030405060708"


_AES_Startup()
ConsoleWrite(cripta("test") & @CRLF)


Func cripta($Data)
    Global $mainKey, $mainIV
    $Key = _Base64Decode($mainKey)
    Return BinaryToString(_Base64Encode(_AesEncrypt($Key, $Data,  $AES_CBC_MODE, $mainIV)))
EndFunc

But when I try to execute in php I get:

echo cripta('test'); // OUTPUT: CB5j5NHA9vQibaGgmvnNTA==

And when I try in execute in autoit:

ConsoleWrite(cripta("test") & @CRLF) ;OUTPUT: MDEwMjAzMDQwNTA2MDcwOOSAx7xqqmIcIU5UI4ZDItw=

Why are those so different? 
Can someone please help me, thank you ;)
 

Link to comment
Share on other sites

Looks like a func challenge/exercise.  

Without having time to dig in a test things, here are some initial thoughts on how I'd troubleshoot it (from a bottom-up approach).

Did you verify that the _Base64Decode and base64decode functions are returning the same cleartext password?
I'm not sure how you'd verify this, but is Wards UDF using AES 128 AFAYK?
I suspect (maybe) how Ward is preparing the IV is different than how the PHP function works (also not sure how to test)....You could probably hack something together to try and ensure that you provide the same binary value to both functions and see what comes out.
 

Link to comment
Share on other sites

  • 1 year later...

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

×
×
  • Create New...