本文整理了Java中org.mindrot.jbcrypt.BCrypt.gensalt()
方法的一些代码示例,展示了BCrypt.gensalt()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BCrypt.gensalt()
方法的具体详情如下:
包路径:org.mindrot.jbcrypt.BCrypt
类名称:BCrypt
方法名:gensalt
[英]Generate a salt for use with the BCrypt.hashpw() method, selecting a reasonable default for the number of hashing rounds to apply
[中]生成一种盐,与BCrypt一起使用。hashpw()方法,为要应用的哈希轮数选择一个合理的默认值
代码示例来源:origin: hierynomus/sshj
/**
* Generate a salt for use with the BCrypt.hashpw() method,
* selecting a reasonable default for the number of hashing
* rounds to apply
* @return an encoded salt value
*/
public static String gensalt() {
return gensalt(GENSALT_DEFAULT_LOG2_ROUNDS);
}
代码示例来源:origin: hierynomus/sshj
/**
* Generate a salt for use with the BCrypt.hashpw() method
* @param log_rounds the log2 of the number of rounds of
* hashing to apply - the work factor therefore increases as
* 2**log_rounds.
* @return an encoded salt value
*/
public static String gensalt(int log_rounds) {
return gensalt(log_rounds, new SecureRandom());
}
代码示例来源:origin: apache/nifi
@Override
public byte[] generateSalt() {
return BCrypt.gensalt(workFactor).getBytes(StandardCharsets.UTF_8);
}
代码示例来源:origin: jenkinsci/jenkins
public String encodePassword(String rawPass, Object obj) throws DataAccessException {
return BCrypt.hashpw(rawPass,BCrypt.gensalt());
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
public String hash(String password) {
return hash(password, BCrypt.gensalt(this.saltSize));
}
代码示例来源:origin: apache/usergrid
@Override
public byte[] hash( byte[] input, CredentialsInfo info, UUID userId, UUID applicationId ) {
return BCrypt.hashpw(new String(input, UTF8), BCrypt.gensalt(defaultIterations)).getBytes();
}
代码示例来源:origin: SonarSource/sonarqube
@Override
public void storeHashPassword(UserDto user, String password) {
requireNonNull(password, "Password cannot be null");
user.setHashMethod(HashMethod.BCRYPT.name())
.setCryptedPassword(BCrypt.hashpw(password, BCrypt.gensalt(12)))
.setSalt(null);
}
}
代码示例来源:origin: hierynomus/sshj
/**
* Test method for 'BCrypt.gensalt()'
*/
public void testGensalt() {
System.out.print("BCrypt.gensalt(): ");
for (int i = 0; i < test_vectors.length; i += 4) {
String plain = test_vectors[i][0];
String salt = BCrypt.gensalt();
String hashed1 = BCrypt.hashpw(plain, salt);
String hashed2 = BCrypt.hashpw(plain, hashed1);
assertEquals(hashed1, hashed2);
System.out.print(".");
}
System.out.println("");
}
代码示例来源:origin: hierynomus/sshj
/**
* Test method for 'BCrypt.gensalt(int)'
*/
public void testGensaltInt() {
System.out.print("BCrypt.gensalt(log_rounds):");
for (int i = 4; i <= 12; i++) {
System.out.print(" " + Integer.toString(i) + ":");
for (int j = 0; j < test_vectors.length; j += 4) {
String plain = test_vectors[j][0];
String salt = BCrypt.gensalt(i);
String hashed1 = BCrypt.hashpw(plain, salt);
String hashed2 = BCrypt.hashpw(plain, hashed1);
assertEquals(hashed1, hashed2);
System.out.print(".");
}
}
System.out.println("");
}
代码示例来源:origin: hierynomus/sshj
/**
* Test for correct hashing of non-US-ASCII passwords
*/
public void testInternationalChars() {
System.out.print("BCrypt.hashpw w/ international chars: ");
String pw1 = "\u2605\u2605\u2605\u2605\u2605\u2605\u2605\u2605";
String pw2 = "????????";
String h1 = BCrypt.hashpw(pw1, BCrypt.gensalt());
assertFalse(BCrypt.checkpw(pw2, h1));
System.out.print(".");
String h2 = BCrypt.hashpw(pw2, BCrypt.gensalt());
assertFalse(BCrypt.checkpw(pw1, h2));
System.out.print(".");
System.out.println("");
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void authentication_with_bcrypt_with_correct_password_should_work() {
String password = randomAlphanumeric(60);
UserDto user = newUserDto()
.setHashMethod(BCRYPT.name())
.setCryptedPassword(BCrypt.hashpw(password, BCrypt.gensalt(12)));
underTest.authenticate(db.getSession(), user, password, AuthenticationEvent.Method.BASIC);
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void authentication_with_bcrypt_with_incorrect_password_should_throw_AuthenticationException() {
String password = randomAlphanumeric(60);
UserDto user = newUserDto()
.setHashMethod(BCRYPT.name())
.setCryptedPassword(BCrypt.hashpw(password, BCrypt.gensalt(12)));
expectedException.expect(AuthenticationException.class);
expectedException.expectMessage("wrong password");
underTest.authenticate(db.getSession(), user, "WHATEVER", AuthenticationEvent.Method.BASIC);
}
代码示例来源:origin: syncthing/syncthing-android
password.setTextContent(BCrypt.hashpw(apikey, BCrypt.gensalt(4)));
changed = true;
代码示例来源:origin: apache/tinkerpop
/**
* Creates or updates a user.
*/
public default GraphTraversal<S, Vertex> user(final String username, final String password) {
return has(VERTEX_LABEL_USER, PROPERTY_USERNAME, username).
fold().
coalesce(__.unfold(),
__.addV(VERTEX_LABEL_USER).property(PROPERTY_USERNAME, username)).
property(PROPERTY_PASSWORD, BCrypt.hashpw(password, BCrypt.gensalt(CredentialTraversalDsl.BCRYPT_ROUNDS)));
}
}
代码示例来源:origin: actframework/actframework
/**
* Generate a salt for use with the BCrypt.hashpw() method,
* selecting a reasonable default for the number of hashing
* rounds to apply
* @return an encoded salt value
*/
public static String gensalt() {
return gensalt(GENSALT_DEFAULT_LOG2_ROUNDS);
}
代码示例来源:origin: apache/tinkerpop
/**
* Creates or updates a user.
*/
public GraphTraversal<Vertex, Vertex> user(final String username, final String password) {
return this.clone().V().
has(VERTEX_LABEL_USER, PROPERTY_USERNAME, username).
fold().
coalesce(__.unfold(),
__.addV(VERTEX_LABEL_USER).property(PROPERTY_USERNAME, username)).
property(PROPERTY_PASSWORD, BCrypt.hashpw(password, BCrypt.gensalt(CredentialTraversalDsl.BCRYPT_ROUNDS)));
}
}
代码示例来源:origin: actframework/actframework
/**
* Generate a salt for use with the BCrypt.hashpw() method
* @param log_rounds the log2 of the number of rounds of
* hashing to apply - the work factor therefore increases as
* 2**log_rounds.
* @return an encoded salt value
*/
public static String gensalt(int log_rounds) {
return gensalt(log_rounds, new SecureRandom());
}
代码示例来源:origin: actframework/actframework
/**
* Generate crypted hash of give password
* @param password the password
* @return the password hash
*/
public String passwordHash(String password) {
if (null == password) {
return null;
}
return BCrypt.hashpw(password, BCrypt.gensalt());
}
代码示例来源:origin: Erudika/para
/**
* bcrypt hash function implemented by Spring Security.
*
* @param s the string to be hashed
* @return the hash
*/
public static String bcrypt(String s) {
return (s == null) ? s : BCrypt.hashpw(s, BCrypt.gensalt(12));
}
代码示例来源:origin: info.magnolia/magnolia-core
public static String getBCrypt(String text) {
// gensalt's log_rounds parameter determines the complexity
// the work factor is 2^log_rounds, and the default is 10
return BCrypt.hashpw(text, BCrypt.gensalt(12));
}
内容来源于网络,如有侵权,请联系作者删除!