title: Bash OpenSSL is not equal to php openssl_encrypt value
body: <p>I am trying to reach the same value of encryption in bash  as it is from php , with no success .</p>
  <p>Here is my php script</p>
  <pre><code>
  
  
  
  
  
  $message ='{&quot;coupon_key&quot;:&quot;011205358365345679&quot;,&quot;location_id&quot;:&quot;288&quot;,&quot;device_key&quot;:&quot;test_1234&quot;}';
  
  $key = &quot;password&quot;;
  
  $iv = base64_decode(&quot;dU+AyWweQYhAlGKLaxoS9w==&quot;);
  
  
  
  
      $base64_iv = base64_encode($iv);
      
      $base64_ev = base64_encode($encrypted_value);
   
  
  
      $encrypted_value = openssl_encrypt(
          $message,
          'AES-256-CBC',
          $key,
          OPENSSL_RAW_DATA|OPENSSL_NO_PADDING,
          $iv
      );
  
  
      $encode = base64_encode($encrypted_value);
  
  //Zi7UcBwqM+gKZC9iZPgF3UHBXLUg1+Age/1+kRIfcstYBgGfYm7N1qCIFnm6jGn4AGQph/Q6hKjR1hYBT0wkJv8c8qFrHHZNUuraMfSRH3s=
  
     
      $mac = hash_hmac('sha256', $base64_iv . $encode, $key);
      
  
  
  
      echo '{&quot;iv&quot;:&quot;'.$base64_iv.'&quot;,&quot;value&quot;:&quot;'.$encode.'&quot;,&quot;mac&quot;:&quot;'.$mac.'&quot;}'.&quot;&lt;br&gt;&quot;;
  
      //{&quot;iv&quot;:&quot;dU+AyWweQYhAlGKLaxoS9w==&quot;,&quot;value&quot;:&quot;Zi7UcBwqM+gKZC9iZPgF3UHBXLUg1+Age/1+kRIfcstYBgGfYm7N1qCIFnm6jGn4AGQph/Q6hKjR1hYBT0wkJv8c8qFrHHZNUuraMfSRH3s=&quot;,&quot;mac&quot;:&quot;97fb6f4226a917322c7361af1d9b2949ad96691c1fc1a7f1c8379c71ae19f356&quot;}
     
      $retString2 =  base64_encode('{&quot;iv&quot;:&quot;'.$base64_iv.'&quot;,&quot;value&quot;:&quot;'.$encode.'&quot;,&quot;mac&quot;:&quot;'.$mac.'&quot;}');
      echo $retString2;
      //eyJpdiI6ImRVK0F5V3dlUVloQWxHS0xheG9TOXc9PSIsInZhbHVlIjoiWmk3VWNCd3FNK2dLWkM5aVpQZ0YzVUhCWExVZzErQWdlLzEra1JJZmNzdFlCZ0dmWW03TjFxQ0lGbm02akduNEFHUXBoL1E2aEtqUjFoWUJUMHdrSnY4YzhxRnJISFpOVXVyYU1mU1JIM3M9IiwibWFjIjoiOTdmYjZmNDIyNmE5MTczMjJjNzM2MWFmMWQ5YjI5NDlhZDk2NjkxYzFmYzFhN2YxYzgzNzljNzFhZTE5ZjM1NiJ9
  
  
  </code></pre>
  <p>and here is my bash version</p>
  <pre><code>password=&quot;password&quot;;
  passwordhex=$(echo &quot;$password&quot; | xxd  -c 256 -ps) ;
  
  # iv2=$(hexdump -n 16 -e '4/4 &quot;%08X&quot; 1 &quot;\n&quot;' /dev/random) ;
  
  iv=$(printf  'dU+AyWweQYhAlGKLaxoS9w==' | base64 -d )
  
  
  
  biv=$(printf &quot;$iv&quot; | base64) ;
  hexiv=$(printf  &quot;$iv&quot; | xxd  -c 256 -ps) ;
  eString=$(printf '{&quot;coupon_key&quot;:&quot;011205358365345678&quot;,&quot;location_id&quot;:&quot;288&quot;,&quot;device_key&quot;:&quot;test_1234&quot;}');
  tttw=$(printf &quot;$eString&quot; | openssl aes-256-cbc -e   -nosalt -a -A -K   &quot;$passwordhex&quot;  -iv &quot;$hexiv&quot;) ;
  echo &quot;$tttw&quot; ;
  
  printf &quot;${biv}${tttw}&quot; |openssl dgst -sha256 -hmac abc -macopt hexkey:&quot;$passwordhex&quot; | sed 's/^.* //';
  
  macopt2=$(printf &quot;${biv}${tttw}&quot; |openssl dgst -sha256 -hmac abc -macopt hexkey:&quot;$passwordhex&quot; | sed 's/^.* //');
  
  echo &quot;$macopt2&quot;
  
  finalString=&quot;{'iv':'$biv','value':'$tttw','mac':'$macopt2'}&quot;;
  echo &quot;$finalString&quot;;
  sendHash=$(printf &quot;$finalString&quot; | base64 -w 0)
  echo &quot;$sendHash&quot;
  
  
  </code></pre>
  <p>Starting from
  tttw=$(echo -n $eString | openssl aes-256-cbc -e   -nosalt -a -A -K   $passwordhex  -iv $hexiv) ;</p>
  <p>it goes wrong , because $tttw is returning then</p>
  <p><code>bKG5quB9/YQUsmlFvDHq2H+AfNGQuDfVztyi0dd5hCY7hLfaACnjD8SWlwqy0yy4hXUZSA2YcTXej/xtMg9vqEpoO6CDw9hk7+tUcYOOV5aOdVBnSLowmEllHt0JfjdE</code>
  instead of <code>Zi7UcBwqM+gKZC9iZPgF3UHBXLUg1+Age/1+kRIfcstYBgGfYm7N1qCIFnm6jGn4AGQph/Q6hKjR1hYBT0wkJv8c8qFrHHZNUuraMfSRH3s=</code></p>
  <p>Can anybody maybe see what option is going wrong here?</p>
  <p>Note1: I have updated the bash script to use prinf instead of echo -n</p>
  <p>Note 2 : Seems on my newer machine I get &quot;hex string is too short, padding with zero bytes to length&quot;  from the line</p>
  <pre><code> tttw=$(printf $eString | openssl aes-256-cbc -e   -nosalt -a -A -K   $passwordhex  -iv $hexiv) ;
  
  </code></pre>