title: openssl- decrypting a base64 string with a key and IV
body: <p>I'm trying to decrypt a base64 string which has been encrypted with aes256 in openssl. I was given the session key and IV, which were encrypted with my key. I converted them to hexadecimal so that I can use the following openssl command:</p>
  
  <pre><code>openssl enc -d -aes256 -iv iv.hex -K sessionkey.hex -in message.b64 -out message.txt
  </code></pre>
  
  <p>I get the error saying the IV is a non-hex value. I started out with IV and session key in base64, which was encrypted with my key. So I did the following:</p>
  
  <p>//convert base64 to binary</p>
  
  <pre><code>openssl base64 -d -in iv.b64 -out iv.bin
  openssl base64 -d -in sessionkey.b64 -out sessionkey.bin
  </code></pre>
  
  <p>//decrypt using my private key</p>
  
  <pre><code>openssl rsautl -decrypt -inkey mykey.pem -in sessionkey.bin -out sessionkey_out.bin
  openssl rsautl -decrypt -inkey mykey.pem -in iv.bin -out iv_out.bin
  </code></pre>
  
  <p>//convert to hex using the following C code:</p>
  
  <h1>include </h1>
  
  <pre><code>main()
  {
   int c;
          while ((c=getchar())!=EOF)
                  printf("%02X",c);
  }
  </code></pre>
  
  <p>//use the hex IV and key to decrypt the message</p>
  
  <pre><code>openssl enc -d -aes256 -iv iv.hex -K sessionkey.hex -in message.b64 -out message.txt
  </code></pre>
  
  <p>I get the error at the last step, saying the IV is non-hex. Any ideas?</p>