title: Running Base64 command works in terminal but not in bash script. Trying to decypher an AES 256 encrypted string
body: <p>I am trying to decypher an AES-256-CBC encrypted string using OpenSSL. My encrypted string is encrypted using c# code mentioned here (<a href="https://stackoverflow.com/questions/5452422/openssl-encryption-using-net-classes/5454692">OpenSSL encryption using .NET classes</a>)</p>
  <p>I first tried decrypting using the following openssl command as below,</p>
  <p><code>openssl enc -d -base64 -aes-256-cbc -md md5 -pass pass:mypass -in my_file.sh_enc -out myfile.sh</code></p>
  <p>but this command returns an error as,</p>
  <p><code>error reading input file</code></p>
  <p>so instead of <strong>-base64</strong> I tried using <strong>-A</strong> as well as <strong>-a</strong> but both command returns <strong>bad magic number</strong>.</p>
  <p>I searched for a while and found that I need to decode the base64 string first and then decrypt. So I ran the command,</p>
  <p><code> base64 -d my_file.sh_enc | openssl enc -d -aes-256-cbc -md md5 -pass pass:mypass -out myfile.sh</code></p>
  <p>This command worked perfectly when tried to execute as such from the terminal. (Ubuntu 20.04).</p>
  <p>But when I add the same command in a .sh bash script, I am getting an error as,</p>
  <pre><code>WARNING:deprecated key derivation used.
  Using -iter or -pbkdf2 would be better.
  bad decrypt
  140285552608576:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:../crypto/evp/evp_enc.c:610:
  </code></pre>
  <p>I tried to store the base64 result in a temp file and then pass the temp file to OpenSSL as <strong>-in</strong> arg, but still, I'm facing the same issue. Can anyone please help me understand and also provide a solution on how to tackle this?</p>
  <p>(please forgive me if my explanation is not proper. Please leave a comment and I'll try to elaborate it on what is not understood)</p>
  <p>Update 1 : Below is my bash file
  <a href="https://i.stack.imgur.com/5L2wR.png" rel="nofollow noreferrer">My bash script</a></p>