I am trying to send an encrypted plain text to SOAP api to get a response.
The API takes actual text and the encrypted text as input. Below is the code i've and it does return an encrypted text however it doesn't match with o/p from the online tool : https://www.devglan.com/online-tools/triple-des-encrypt-decrypt The API request works if I use the O/p from the online tool but doesnt if I use the text from python code.
from Crypto.Cipher import DES3
from Crypto import Random
from base64 import b64encode, b64decode
key = 'GHYZXFZH2A4B6N6P7R9SPNMT'
cipher_encrypt = DES3.new(key, DES3.MODE_ECB)
plaintext = 'hellomyf'
encrypted_text = cipher_encrypt.encrypt(plaintext)
ct = b64encode(encrypted_text).decode('utf-8')
print(ct)
byte_string = b64decode(ct)
pt = cipher_encrypt.decrypt(byte_string)
o/p from script
jqbhxNmunio=
o/p from tool
jqbhxNmunioWRmE3XhbiHg==
I am trying to understand what am I missing in the code why does the length of the online web tool is higher than the length of the text from python code?
Your help would be greatly appreciated. Thank you
Answer
After adding a 8 bit pad like below it did match
pad(plaintext.encode('utf-8'), block_size, style='pkcs7')