Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 9th, 2012  |  syntax: C#  |  size: 0.84 KB  |  hits: 34  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public string EncodePassword(string password, string salt)
  2.         {
  3.             byte[] bytes = Encoding.Unicode.GetBytes(password);
  4.             byte[] src = Encoding.Unicode.GetBytes(salt);
  5.             byte[] dst = new byte[src.Length + bytes.Length];
  6.  
  7.             Buffer.BlockCopy(src, 0, dst, 0, src.Length);
  8.             Buffer.BlockCopy(bytes, 0, dst, src.Length, bytes.Length);
  9.  
  10.             HashAlgorithm algorithm = HashAlgorithm.Create("SHA1");
  11.  
  12.             byte[] inArray = algorithm.ComputeHash(dst);
  13.  
  14.             return Convert.ToBase64String(inArray);
  15.         }
  16.  
  17.         private byte[] createSalt(byte[] saltSize)
  18.         {
  19.             byte[] saltBytes = saltSize;
  20.  
  21.             RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
  22.  
  23.             rng.GetNonZeroBytes(saltBytes);
  24.             return saltBytes;
  25.         }