title: AES/ECB/PKCS5Padding encryption in python
body: <p>I am trying to encrypt using algorithm AES/CBC/PKCS5PADDING in python. I am getting correct data using online tool <a href="https://8gwifi.org/CipherFunctions.jsp" rel="nofollow noreferrer">https://8gwifi.org/CipherFunctions.jsp</a> but unable to implement it in a python. Please find below my code snippet.</p>
  <pre><code>from Crypto.Cipher import AES
  import base64
  import re
  
  DEFAULT_KEY = 'dkdlko9876543210'
  
  
  class AesCbc:
  
      def __init__(self, key=None):
          self.key = key or DEFAULT_KEY
          self.mode = AES.MODE_CBC
          self.size = AES.block_size
          self.pad = lambda s: s + (self.size - len(s) % self.size) * chr(self.size - len(s) % self.size)
  
      def encrypt(self, content):
          cryptor = AES.new(self.key, self.mode, self.key)
          encrypted = cryptor.encrypt(self.pad(content))
          return base64.urlsafe_b64encode(encrypted)
  
      def decrypt(self, content):
          cryptor = AES.new(self.key, self.mode, self.key)
          content += (len(content) % 4) * '='
          content = base64.urlsafe_b64decode(content)
          decrypted = cryptor.decrypt(content)
          try:
              return re.compile('[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f\n\r\t]').sub('', decrypted.decode())
          except Exception:
              raise ValueError(&quot;inputted value can not be decrypted.&quot;)
  
  test = AesCbc()
  
  print(test.encrypt(&quot;value&quot;))
  </code></pre>
  <p>But result differs. I want to achieve AES/CBC/PKCS5PADDING encryption same as on <a href="https://8gwifi.org/CipherFunctions.jsp" rel="nofollow noreferrer">https://8gwifi.org/CipherFunctions.jsp</a>. Please help me in implementing the same algorithm in python script as well.</p>