title: ASP.NET membership salt?
body: <p>How does ASP.NET membership generate their salt key and then how do they encode it (that is, is it salt + password or password + salt)?</p>
  
  <p>I am using <a href="http://en.wikipedia.org/wiki/SHA-1" rel="noreferrer">SHA-1</a> with my membership, but I would like to recreate the same salts so the built-in membership stuff could hash the stuff the same way as my stuff can.</p>
  
  <p><strong>Edit 2:</strong> Never mind. I misread it and was thinking it said bytes, not bits. So I was passing in 128 bytes, not 128 bits.</p>
  
  <p><strong>Edit:</strong> I been trying to make it so. This is what I have,</p>
  
  <pre class="lang-cs prettyprint-override"><code>public string EncodePassword(string password, string salt)
  {
      byte[] bytes = Encoding.Unicode.GetBytes(password);
      byte[] src = Encoding.Unicode.GetBytes(salt);
      byte[] dst = new byte[src.Length + bytes.Length];
  
      Buffer.BlockCopy(src, 0, dst, 0, src.Length);
      Buffer.BlockCopy(bytes, 0, dst, src.Length, bytes.Length);
  
      HashAlgorithm algorithm = HashAlgorithm.Create("SHA1");
  
      byte[] inArray = algorithm.ComputeHash(dst);
  
      return Convert.ToBase64String(inArray);
  }
  
  private byte[] createSalt(byte[] saltSize)
  {
      byte[] saltBytes = saltSize;
  
      RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
      rng.GetNonZeroBytes(saltBytes);
  
      return saltBytes;
  }
  </code></pre>
  
  <p>So I have not tried to see if the ASP.NET membership will recognize this yet the hashed password looks close. I just don't know how to convert it to base64 for the salt.</p>
  
  <p>I did this</p>
  
  <pre class="lang-cs prettyprint-override"><code>byte[] storeSalt = createSalt(new byte[128]);
  string salt = Encoding.Unicode.GetString(storeSalt);
  string base64Salt = Convert.ToBase64String(storeSalt);
  
  int test = base64Salt.Length;
  </code></pre>
  
  <p>Test length is 172 which is well over the 128 bits so what am I doing wrong?</p>
  
  <p>This is what their salt looks like</p>
  
  <pre class="lang-text prettyprint-override"><code>vkNj4EvbEPbk1HHW+K8y/A==
  </code></pre>
  
  <p>This is what my salt looks like</p>
  
  <pre class="lang-none prettyprint-override"><code>E9oEtqo0livLke9+csUkf2AOLzFsOvhkB/NocSQm33aySyNOphplx9yH2bgsHoEeR/aw/pMe4SkeDvNVfnemoB4PDNRUB9drFhzXOW5jypF9NQmBZaJDvJ+uK3mPXsWkEcxANn9mdRzYCEYCaVhgAZ5oQRnnT721mbFKpfc4kpI=
  </code></pre>