/** * Creates a 60 character Bcrypt String, including * version, cost factor, salt and hash, separated by '$' * * @param version the version, 2y,2b or 2a. (2a is not backwards compatible.) * @param cost the cost factor, treated as an exponent of 2 * @param salt a 16 byte salt * @param password the password * @return a 60 character Bcrypt String */ private static string CreateBcryptString(string version, byte[] password, byte[] salt, int cost) { if (!AllowedVersions.Contains(version)) { throw new ArgumentException("Version " + version + " is not accepted by this implementation.", "version"); } StringBuilder sb = new StringBuilder(60); sb.Append('$'); sb.Append(version); sb.Append('$'); sb.Append(cost < 10 ? ("0" + cost) : cost.ToString()); sb.Append('$'); sb.Append(EncodeData(salt)); byte[] key = BCrypt.Generate(password, salt, cost); sb.Append(EncodeData(key)); return(sb.ToString()); }