title: How to get random salt from OpenSSL as std::string
body: <p>I would like to generate a random string with OpenSSL and use this as a salt in a hashing function afterwards (will be Argon2). Currently I'm generating the random data this way:</p>
  
  <pre><code>if(length &lt; CryptConfig::sMinSaltLen){        
      return 1;
  }
  if (!sInitialized){
      RAND_poll();
      sInitialized = true;
  }
  
  unsigned char * buf = new unsigned char[length];
  if (!sInitialized || !RAND_bytes(buf, length)) {      
      return 1;
  }
  
  salt = std::string (reinterpret_cast&lt;char*&gt;(buf));
  delete buf;
  
  return 0;
  </code></pre>
  
  <p>But a <code>std::cout</code> of salt doesn't seem to be a proper string (contains control symbols and other stuff). This is most likely only my fault.</p>
  
  <p>Am I using the wrong functions of OpenSSL to generate the random data? </p>
  
  <p>Or is my conversion from <code>buf</code> to string faulty?</p>