title: byte array to string in java
body: <pre><code>SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
  byte[] salt = new byte[16];
  random.nextBytes(salt);
  </code></pre>
  
  <p>I would like to convert salt to a string to store/read. I don't seem to be able to get this to work. I have read that I need to use the right encoding but I'm not sure what encoding to use. I have tried the following but get junk:</p>
  
  <pre><code>String s = new String(salt, "UTF-8");
  String s = new String(salt, "UTF-16");
  String s = new String(salt);
  </code></pre>
  
  <p>Edit: For context, I'm trying to work through and understand <a href="http://www.javacodegeeks.com/2012/05/secure-password-storage-donts-dos-and.html" rel="nofollow">this</a> code. I'm trying to view the salt and password so I can monkey with the code. </p>