Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Online tool and Python Script have two different AES cipher text result?

I wrote the following program to encrypt my data using AES algorithm in CBC mode:

import hmac
import base64
import hashlib
from Crypto.Cipher import AES   

AES_KEY = "\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF"
IV = "\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF"

print "KEY: ",
for i in AES_KEY:
    print str(i).encode("hex"),
print

print "IV:  ",
for i in IV:
    print str(i).encode("hex"),
print

# Encryption
def aes_encrypt(plain, key, iv):
    AES.key_size =16
    encryption_suite = AES.new(key, AES.MODE_CBC, iv)
    cipher_text = encryption_suite.encrypt(plain)
    return cipher_text

# Decryption
def aes_decrypt(cipher, key, iv):
    decryption_suite = AES.new(key, AES.MODE_CBC, iv)
    plain_text = decryption_suite.decrypt(cipher)
    return plain_text

result = aes_encrypt("testtesttesttest",AES_KEY,IV)

print "OUT: ",
for l in result:
    print str(l).encode("hex"),

But when I check its output with this online tool, they are not equal:

My program output:

Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>> 
KEY:  00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff
IV:   00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff
OUT:  90 e6 d6 31 61 66 eb dd ad 48 53 e8 a0 ca c6 48
>>> 

The Online tool: enter image description here Why?

like image 300
Ebrahim Ghasemi Avatar asked Dec 04 '25 15:12

Ebrahim Ghasemi


1 Answers

Your code uses key 00112233445566778899AABBCCDDEEFF but you use another key on the web namly 00112233445566778899AABBCCEEDDFF

where DD and EE are switched. The same goes for the Initialization vector.

like image 199
Ebbe M. Pedersen Avatar answered Dec 06 '25 07:12

Ebbe M. Pedersen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!