title: OpenSSL decrypt AES 256bit (base64) encrypted password - wrong final block length
body: <p>I am trying to decrypt aes-256-cdc encoded password using OpenSSL</p>
  
  <pre><code>#!/usr/bin/env bash
  
  ak=BgL0cPoZQ4wZWOWl5mXBhlMsNbbZL2zvsWZXjuGy4Iw=
  iv=cGEvcGWzE8t7CS3wbeoUFQ==
  pass=RCQm23YHOCg3nxOl7CcQ7w==
  
  #change format from base64 into hex
  AES_KEY=<span class="math-container">$(echo "$</span>{ak}" | openssl base64 -d | xxd -p |tr -d '\n')
  AES_IV=<span class="math-container">$(echo "$</span>{iv}" | openssl base64 -d | xxd -p)
  ENCODED_PASSWORD=<span class="math-container">$(echo "$</span>{pass}" | openssl base64 -d | xxd -p)
  
  echo "AES_KEY <span class="math-container">${AES_KEY}"
  echo "AES_IV $</span>{AES_IV}"
  echo "ENCODED_PASSWORD ${ENCODED_PASSWORD}"
  
  #set password file
  echo "${ENCODED_PASSWORD}" &gt; in.txt
  
  #decode password
  openssl enc -nosalt -aes-256-cbc -d -iv <span class="math-container">${AES_IV} -K $</span>{AES_KEY} -in in.txt
  </code></pre>
  
  <p>this results in error message </p>
  
  <pre><code>AES_KEY 0602f470fa19438c1958e5a5e665c186532c35b6d92f6cefb166578ee1b2e08c
  AES_IV 70612f7065b313cb7b092df06dea1415
  ENCODED_PASSWORD 53b7adff6e85baedfa9dab80109ad67d
  ▒▒▒▒▒▒`$;▒▒▒▒%▒O▒Q▒▒▒S▒▒&lt;7 7
                              bad decrypt
  32624:error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length:evp_enc.c:518:
  0602f470fa19438c1958e5a5e665c186532c35b6d92f6cefb166578ee1b2
  e08c
  </code></pre>
  
  <p>I think that the problem is aes-key (ak) which has a newline char in it, which I am trying to remove with </p>
  
  <pre><code>|tr -d '\n'
  </code></pre>
  
  <p>a password should decode as </p>
  
  <pre><code>password
  </code></pre>