title: What is the format of a Password Salt string for MD5 hash?
body: <p>I am creating a simple DB access application using C++, and I have added Users Table containing: <strong>ID</strong>, <strong>USER</strong>, <strong>PASSWORD</strong> and <strong>SALT</strong>, and I am using <strong>Crypto++</strong> as crypto backend. So I created this function:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include "crypto.h"
  
  #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
  #include &lt;md5.h&gt;
  #include &lt;hex.h&gt;
  #include &lt;osrng.h&gt;
  
  using namespace std;
  using namespace CryptoPP;
  
  string MyCrypto::MD5(const string strMessage)
  {
      byte arrbyDigest[Weak::MD5::DIGESTSIZE];
      Weak::MD5 hash;
      hash.CalculateDigest(arrbyDigest, /*(const byte*)*/strMessage.c_str(), strMessage.length());
  
      HexEncoder encoder;
      string strOutput;
  
      encoder.Attach(new StringSink(strOutput));
      encoder.Put(arrbyDigest, sizeof(arrbyDigest));
      encoder.MessageEnd();
  
      return strOutput;
  }
  
  string MyCrypto::GenerateSalt(const size_t length /*= 16*/)
  {
      SecByteBlock arrbySalt(length);
      AutoSeededRandomPool asrp;
      asrp.GenerateBlock(arrbySalt, length);
  
      string strSalt(arrbySalt);
      strSalt.ToAscii();
  
      return strSalt;
  }
  </code></pre>
  
  <p>So good so far, all is working fine until I realized that the generated salt string can contain <strong>non-printable characters</strong> even <strong>null termination character</strong></p>
  
  <p>So my questions are:</p>
  
  <p>Am I doing it the right way ?</p>
  
  <p>Is the length of the salt <strong>16</strong> as I did the practical way ?</p>
  
  <p>Should I encrypt the salt string in <strong>Base 64</strong>, <strong>HEX</strong> or leave it as <strong>plain text</strong> when concatenating it with the plain password string before the MD5 hash ?</p>
  
  <p>Should I encrypt the salt string in <strong>Base 64</strong>, <strong>HEX</strong> or leave it as <strong>plain text</strong> when saving it to the database ?</p>
  
  <p>What are your suggestions ?</p>