title: Question regarding encryption of files using RC4 using hexadecimal keys
body: <p>I am having to encrypt a binary file using RC4 algorithm for my script (written in bash)</p>
  
  <p>The key is also in binary format</p>
  
  <p>The following is what I am doing:</p>
  
  <pre><code>    echo -n -e $bPacketh &gt; /tmp/packet
      echo -n -e $clientWriteKeyb &gt; /tmp/cwkey
      mach=`openssl dgst -binary -hmac -md5 /tmp/cwkey /tmp/packet` 
      pkth=`openssl enc -e -rc4 -K /tmp/cwkey -in /tmp/packet`
  </code></pre>
  
  <p>The contents of /tmp/packet and /tmp/cwkey are as follows:</p>
  
  <pre><code>    &gt;cat /tmp/packet | od -t x1
  
      0000000 86 09 94 8b cf 2d d3 99 94 9f 72 60 dd 3f a6 b6
      0000020 01 00 00 00 13 0b 05 00 00 00 0c 73 73 68 2d 75
      0000040 73 65 72 61 75 74 68 22 68 fb ab 5e 4d 1b 2b 61
      0000060 bd 38
      0000062
  
      &gt;cat /tmp/cwkey | od -t x1 
  
      0000000 5d c5 45 a8 2b 44 5d 2f 49 67 f5 71 73 a8 51 5c
      0000020
  </code></pre>
  
  <p>The MAC calculation command succeeds, but the encrypted packet calculation command gives the following error:</p>
  
  <pre><code>    &gt;openssl enc -e -rc4 -K /tmp/cwkey -in /tmp/packet
  
      non-hex digit
      invalid hex key value
  </code></pre>
  
  <p>I searched through forums and found that the format of key should be "0001020304..." but I am not sure how to convert my key (/tmp/cwkey above) to that format</p>
  
  <p>Request you to please help me out</p>