Guest User

BCrypt GeneratePassword - slat er del af hashed

a guest
Jun 16th, 2012
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. int rounds = Int32.Parse(salt.Substring(offset, 2), NumberFormatInfo.InvariantInfo);
  2.  
  3.         byte[] passwordBytes = Encoding.UTF8.GetBytes(password + (minor >= 'a' ? "\0" : String.Empty));
  4.         byte[] saltBytes = DecodeBase64(salt.Substring(offset + 3, 22),
  5.                                         BCRYPT_SALT_LEN);
  6.  
  7.         BCrypt bcrypt = new BCrypt();
  8.  
  9.         byte[] hashed = bcrypt.CryptRaw(passwordBytes, saltBytes, rounds);
  10.  
  11.         StringBuilder rs = new StringBuilder();
  12.  
  13.         rs.Append("$2");
  14.         if (minor >= 'a') {
  15.             rs.Append(minor);
  16.         }
  17.         rs.Append('$');
  18.         if (rounds < 10) {
  19.             rs.Append('0');
  20.         }
  21.         rs.Append(rounds);
  22.         rs.Append('$');
  23.         rs.Append(EncodeBase64(saltBytes, saltBytes.Length));
  24.         rs.Append(EncodeBase64(hashed,
  25.                                (bf_crypt_ciphertext.Length * 4) - 1));
  26.  
  27.         return rs.ToString();
Advertisement
Add Comment
Please, Sign In to add comment