MCPcopy Index your code
hub / github.com/bcrypt-ruby/bcrypt-ruby / gensalt

Method gensalt

ext/jruby/bcrypt_jruby/BCrypt.java:818–843  ·  view source on GitHub ↗

Generate a salt for use with the BCrypt.hashpw() method @param prefix the prefix value (default $2a) @param log_rounds the log2 of the number of rounds of hashing to apply - the work factor therefore increases as 2 log_rounds. @param random an instance of SecureRandom to use @return an encoded sa

(String prefix, int log_rounds, SecureRandom random)

Source from the content-addressed store, hash-verified

816 * @exception IllegalArgumentException if prefix or log_rounds is invalid
817 */
818 public static String gensalt(String prefix, int log_rounds, SecureRandom random)
819 throws IllegalArgumentException {
820 StringBuilder rs = new StringBuilder();
821 byte rnd[] = new byte[BCRYPT_SALT_LEN];
822
823 if (!prefix.startsWith("$2") ||
824 (prefix.charAt(2) != 'a' && prefix.charAt(2) != 'y' &&
825 prefix.charAt(2) != 'b')) {
826 throw new IllegalArgumentException ("Invalid prefix");
827 }
828 if (log_rounds < 4 || log_rounds > 31) {
829 throw new IllegalArgumentException ("Invalid log_rounds");
830 }
831
832 random.nextBytes(rnd);
833
834 rs.append("$2");
835 rs.append(prefix.charAt(2));
836 rs.append("$");
837 if (log_rounds < 10)
838 rs.append("0");
839 rs.append(log_rounds);
840 rs.append("$");
841 encode_base64(rnd, rnd.length, rs);
842 return rs.toString();
843 }
844
845 /**
846 * Generate a salt for use with the BCrypt.hashpw() method

Callers 4

testGensaltIntMethod · 0.95
testGensaltMethod · 0.95
generate_saltMethod · 0.80

Calls 1

encode_base64Method · 0.95

Tested by 3

testGensaltIntMethod · 0.76
testGensaltMethod · 0.76