AutoIt для шифрования/дешифрования Python ⇐ Python
AutoIt для шифрования/дешифрования Python
I am trying to communicate from AutoIt with a Python TCP server using encryption, but I think there's something wrong with my algorithms since the results of both encryptions/decryptions are different:
AutoIt:
#include Global $key = "pjqFX32pfaZaOkkCFQuYziOApaBgRE1Y"; Global $str = "Am I welcome???" _Crypt_Startup() $hKey = _Crypt_DeriveKey($key, $CALG_AES_256) $s = _Crypt_EncryptData($str, $hKey, $CALG_USERKEY) $s = _Base64Encode($s) ConsoleWrite("Encrypted: " & $s & @CRLF) $s = _Base64Decode($s) $str = _Crypt_DecryptData($s, $hKey, $CALG_USERKEY) ConsoleWrite("Decrypted: " & BinaryToString($str) & @CRLF) AutoIt Output:
Encrypted: ZFBnThUDPRuIUAPV6vx9Ng== Decrypted: Am I welcome??? Python:
#!/usr/bin/env python from Crypto.Cipher import AES import base64 import binascii BLOCK_SIZE = 16 PADDING = binascii.unhexlify(b"07") pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s))) DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING) secret = 'pjqFX32pfaZaOkkCFQuYziOApaBgRE1Y' cipher=AES.new(key=secret, mode=AES.MODE_ECB) encoded = EncodeAES(cipher, 'Am I welcome???') print 'Encrypted string:', encoded decoded = DecodeAES(cipher, encoded) print 'Decrypted string:', decoded Python output:
Encrypted string: NDJepp4CHh5C/FZb4Vdh4w== Decrypted string: Am I welcome??? The encrypted results are the NOT the same...
Where is my "bug"?
Источник: https://stackoverflow.com/questions/205 ... pt-decrypt
I am trying to communicate from AutoIt with a Python TCP server using encryption, but I think there's something wrong with my algorithms since the results of both encryptions/decryptions are different:
AutoIt:
#include Global $key = "pjqFX32pfaZaOkkCFQuYziOApaBgRE1Y"; Global $str = "Am I welcome???" _Crypt_Startup() $hKey = _Crypt_DeriveKey($key, $CALG_AES_256) $s = _Crypt_EncryptData($str, $hKey, $CALG_USERKEY) $s = _Base64Encode($s) ConsoleWrite("Encrypted: " & $s & @CRLF) $s = _Base64Decode($s) $str = _Crypt_DecryptData($s, $hKey, $CALG_USERKEY) ConsoleWrite("Decrypted: " & BinaryToString($str) & @CRLF) AutoIt Output:
Encrypted: ZFBnThUDPRuIUAPV6vx9Ng== Decrypted: Am I welcome??? Python:
#!/usr/bin/env python from Crypto.Cipher import AES import base64 import binascii BLOCK_SIZE = 16 PADDING = binascii.unhexlify(b"07") pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s))) DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING) secret = 'pjqFX32pfaZaOkkCFQuYziOApaBgRE1Y' cipher=AES.new(key=secret, mode=AES.MODE_ECB) encoded = EncodeAES(cipher, 'Am I welcome???') print 'Encrypted string:', encoded decoded = DecodeAES(cipher, encoded) print 'Decrypted string:', decoded Python output:
Encrypted string: NDJepp4CHh5C/FZb4Vdh4w== Decrypted string: Am I welcome??? The encrypted results are the NOT the same...
Where is my "bug"?
Источник: https://stackoverflow.com/questions/205 ... pt-decrypt
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Мне задали вопрос, как создать шифр для шифрования и дешифрования программы [закрыто]
Anonymous » » в форуме C++ - 0 Ответы
- 39 Просмотры
-
Последнее сообщение Anonymous
-