title: Additional characters in RC4 encryption
body: <p>I am facing an issue when trying to encrypt a string using Open SSL RC4 function. Somme additionnal characters where added at the end of the encrypted string.</p>
  <p>Here is my code :</p>
  <pre><code>RC4_KEY rc4_key;
  QString key= &quot;612c207468652066&quot;;
  
  QByteArray keyData=key.QString::toUtf8();
  unsigned char * mykey=reinterpret_cast&lt;unsigned char *&gt;(keyData.data());
  
  QString input = &quot;7447806cc997966f6b8b59a57c01bfe6fe8381d4fed5628b531fbeb1c4629151722ee712fa906dfea1c68b7015243bfcdd42d3e990c1bd6daa56df620a9d1e441f4ba308da5584e032f06fe925ee9df328fadab0ad2a5869fdea366189a397f72b320a4f11b0cc41cbfaa3b6923f20cc8c4c80d9c9b69eb5e2a6cc2fb9ee2e72ca79f08617b3b5812eddb3f58b68&quot;;
  qDebug()&lt;&lt; &quot;input&quot;&lt;&lt;input &lt;&lt; input.size();
  QByteArray inputData=input.QString::toUtf8();
  unsigned char * ciphertext1= (unsigned char*)malloc(input.size());
  memset(ciphertext1, 0, input.size());
  ciphertext1=reinterpret_cast&lt;unsigned char *&gt;(QByteArray::fromHex(inputData).data());
  printf(&quot;ciphertext1: %s\n&quot;, ciphertext1);
  
  RC4_set_key(&amp;rc4_key,keyData.size() , mykey);
  
  unsigned char * firsthashJson= (unsigned char*)malloc(input.size());
  firsthashJson[input.size()-1]=0x00;
  memset(firsthashJson, 0, input.size());
  RC4(&amp;rc4_key,input.length(),ciphertext1, firsthashJson);
  printf(&quot;Decrypted: %s\n&quot;, firsthashJson);
  
  QString str1 = QString::fromUtf8((char*)firsthashJson);
  </code></pre>
  <p>I obtained the following result: b036fe3eae7881fe135562335f9a##5265705250##b2a475f7a99cf400d34da436d522d9bc5566d8b7a015c7a16ee2d5e730199acf1f61fe2f3d6b9525e1c45acb36383253b4fc&lt; Ú«Í`ã¿rßÖQÕ§ìj‗¤Ì&amp;Öâ¤#&gt;XÏ¸0õ+▲®╩Ä=╚líUm&quot;ód☻Ô1ı┘©ÜLÔ»âH÷/o┐öñ▄|▄ÐÄ┤N  ☻§@ı2w5▒KTâUÆB¢ÏdÔxÚ⌂ê☺°¹╔«▓J)→8èê╔┤║ù@│k       ↕▬↨[║GtUË(♂D</p>
  <p>the expected one is : b036fe3eae7881fe135562335f9a##5265705250##b2a475f7a99cf400d34da436d522d9bc5566d8b7a015c7a16ee2d5e730199acf1f61fe2f3d6b9525e1c45acb36383253b4fc</p>
  <p>Do you have any idea of the source cause of this issue.</p>
  <p>Thanks in advance for your help.</p>
  <p>###############################################################</p>
  <p>@paddy
  Thank you for your help.</p>
  <p>Unfortunately i have the same issue here is the new code:</p>
  <pre><code>RC4_KEY rc4_key;
  QString key= &quot;612c207468652066&quot;;
  
  QByteArray keyData=key.QString::toUtf8();
  unsigned char * mykey=reinterpret_cast&lt;unsigned char *&gt;(keyData.data());
  
  QString input = &quot;7447806cc997966f6b8b59a57c01bfe6fe8381d4fed5628b531fbeb1c4629151722ee712fa906dfea1c68b7015243bfcdd42d3e990c1bd6daa56df620a9d1e441f4ba308da5584e032f06fe925ee9df328fadab0ad2a5869fdea366189a397f72b320a4f11b0cc41cbfaa3b6923f20cc8c4c80d9c9b69eb5e2a6cc2fb9ee2e72ca79f08617b3b5812eddb3f58b68&quot;;
  qDebug()&lt;&lt; &quot;input&quot;&lt;&lt;input &lt;&lt; input.size();
  QByteArray inputData=input.QString::toUtf8();
  unsigned char * ciphertext1= (unsigned char*)malloc(input.size());
  memset(ciphertext1, 0, input.size());
  ciphertext1=reinterpret_cast&lt;unsigned char *&gt;(QByteArray::fromHex(inputData).data());
  printf(&quot;ciphertext1: %s\n&quot;, ciphertext1);
  
  RC4_set_key(&amp;rc4_key,keyData.size() , mykey);
  
  unsigned char * firsthashJson= (unsigned char*)malloc(input.size()+1);
  
  memset(firsthashJson, 0, input.size()+1);
  firsthashJson[input.size()]=0;
  
  RC4(&amp;rc4_key,input.size(),ciphertext1, firsthashJson);
  printf(&quot;Decrypted: %s\n&quot;, firsthashJson);
  
  firsthashJson[input.size()]=0;
  QString str1 = QString::fromUtf8((char*)firsthashJson);
  
  qDebug()&lt;&lt;&quot;final string &quot;&lt;&lt;str1&lt;&lt; str1.size();
  </code></pre>