Jump to content

How to conevert AES python to autoit ( have a sample )

Recommended Posts

from Crypto.Cipher import AES
from Crypto.Hash import SHA256
import argparse
import sys
from base64 import b64encode, b64decode

def encrypt(value, cipher):
    return b64encode(cipher.encrypt(pkcs5_pad(value)))

def pkcs5_pad(s):
    BLOCK_SIZE= 16
    return s + (BLOCK_SIZE - len(s) ) * chr(BLOCK_SIZE - len(s) )

code = "higher_env3"
code1 = "592174f17a037393"
output = "hovkczsxXwdUVV7Ffciwig=="

hashedkey = SHA256.new(code1).digest()
print "hashedkey = %r" % hashedkey

keycipher = AES.new(hashedkey, AES.MODE_ECB)
print "keycipher = %r" % keycipher
print(encrypt(code, keycipher))


Link to post
Share on other sites


welcome to the forum.

Have a look at the function _Crypt_HashData(), requires an "#include <Crypt.au3>". Some of the available hash function value codes are commented out, but work fine:


; crypt.au3

; Global Const $CALG_SHA_256 = 0x0000800c
; Global Const $CALG_SHA_384 = 0x0000800d
; Global Const $CALG_SHA_512 = 0x0000800e

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to post
Share on other sites

I try to wrong output.

#include <Crypt1.au3>
#include "Base64.au3"

Global $key = "592174f07a037393";
Global $str = "higher_env3"

Local $hash = _Base64Encode(_Crypt_HashData($key, $CALG_SHA_256))
ConsoleWrite("hash = " & $hash & @CRLF)

$hKey = _Crypt_DeriveKey($hash, $CALG_AES_256)
$s = _Crypt_EncryptData($str, $hKey, $CALG_USERKEY)

correct in python = mszw/K08roGSqb9X2kSMVQ== 
output autoit = QP8NYMgQxM19cP/sO+4/6w==

Edited by DannyJio
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...