title: Implementing AES/ECB/PKCS5 padding in Python
body: <p>I am trying to implement a python program to encrypt a plain text using AES/ECB/PKCS5 padding. The output I am getting is slightly different from expected.</p>
  <p>Python3 program:</p>
  <pre><code>import base64
  from Crypto.Cipher import AES
  
   
  def add_to_16(value):
      while len(value) % 16 != 0:
          value += '\0'
      return str.encode (value) # returns bytes
   
  
  # Encryption method
  def encrypt(text):
           # Secret key 
      key='92oifgGh893*cj%7' 
  
           # Text to be encrypted
           # Initialize encryptor
      aes = AES.new(key, AES.MODE_ECB) 
  
           # Aes encryption to be
      encrypt_aes = aes.encrypt(add_to_16(text)) 
  
           # Converted into a string with base64
      encrypted_text = str(base64.encodebytes (encrypt_aes), encoding = 'utf-8')
  
      print(encrypted_text)
      return encrypted_text
  
  if __name__ == '__main__': 
  
      text = '{  &quot;Message&quot;: &quot;hello this is a plain text&quot; , &quot;user&quot;:&quot;john.doe&quot;, &quot;Email&quot;:&quot;john.doe@example.com}'
      entrypted_text = encrypt(text)
  
  </code></pre>
  <p>The output for above program is:</p>
  <pre><code>oo8jwHQNQnBwVUsJ5piShFRM3PFFIfULwcoFOEQhPMTAvexSr6eE9aFLVQTpAKBFkGi8vNbtScvyexSxHBlwVapJ5Szz1JPR9q9cHHJYYMzGocln4TRPFQ6S3e8jjVud
  </code></pre>
  <p>where as when verified with 3rd party tools <a href="https://www.devglan.com/online-tools/aes-encryption-decryption" rel="nofollow noreferrer">online</a>, the results is:</p>
  <pre><code>oo8jwHQNQnBwVUsJ5piShFRM3PFFIfULwcoFOEQhPMTAvexSr6eE9aFLVQTpAKBFkGi8vNbtScvyexSxHBlwVapJ5Szz1JPR9q9cHHJYYMwnIIuNCUVn/IExpxebqXV1
  </code></pre>
  <p>Can someone please guide me where I am doing wrong?</p>