org.springframework.security.crypto.bcrypt.BCrypt.gensalt()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中org.springframework.security.crypto.bcrypt.BCrypt.gensalt()方法的一些代码示例,展示了BCrypt.gensalt()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BCrypt.gensalt()方法的具体详情如下:
包路径:org.springframework.security.crypto.bcrypt.BCrypt
类名称:BCrypt
方法名:gensalt

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: spring-projects/spring-security

/**
 * 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: spring-projects/spring-security

/**
 * 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.
 * @param random        an instance of SecureRandom to use
 * @return    an encoded salt value
 * @exception IllegalArgumentException if log_rounds is invalid
 */
public static String gensalt(int log_rounds, SecureRandom random)
    throws IllegalArgumentException {
  return gensalt("$2a", log_rounds, random);
}

代码示例来源:origin: spring-projects/spring-security

public static String gensalt(String prefix) {
  return gensalt(prefix, GENSALT_DEFAULT_LOG2_ROUNDS);
}

代码示例来源:origin: org.springframework.security/spring-security-core

/**
 * 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: spring-projects/spring-security

/**
 * 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.
 * @return    an encoded salt value
 * @exception IllegalArgumentException if prefix or log_rounds is invalid
 */
public static String gensalt(String prefix, int log_rounds)
    throws IllegalArgumentException {
  return gensalt(prefix, log_rounds, new SecureRandom());
}

代码示例来源:origin: spring-projects/spring-security

/**
 * 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
 * @exception IllegalArgumentException if log_rounds is invalid
 */
public static String gensalt(int log_rounds)
    throws IllegalArgumentException {
  return gensalt(log_rounds, new SecureRandom());
}

代码示例来源:origin: org.springframework.security/spring-security-core

/**
 * 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. Minimum 4, maximum 31.
 * @return an encoded salt value
 */
public static String gensalt(int log_rounds) {
  return gensalt(log_rounds, new SecureRandom());
}

代码示例来源:origin: org.springframework.security/spring-security-core

public String encode(CharSequence rawPassword) {
  String salt;
  if (strength > 0) {
    if (random != null) {
      salt = BCrypt.gensalt(strength, random);
    }
    else {
      salt = BCrypt.gensalt(strength);
    }
  }
  else {
    salt = BCrypt.gensalt();
  }
  return BCrypt.hashpw(rawPassword.toString(), salt);
}

代码示例来源:origin: spring-projects/spring-security

public String encode(CharSequence rawPassword) {
  String salt;
  if (strength > 0) {
    if (random != null) {
      salt = BCrypt.gensalt(version.getVersion(), strength, random);
    } else {
      salt = BCrypt.gensalt(version.getVersion(), strength);
    }
  } else {
    salt = BCrypt.gensalt(version.getVersion());
  }
  return BCrypt.hashpw(rawPassword.toString(), salt);
}

代码示例来源:origin: spring-projects/spring-security

@Test(expected = IllegalArgumentException.class)
public void genSaltFailsWithTooFewRounds() {
  BCrypt.gensalt(3);
}

代码示例来源:origin: spring-projects/spring-security

@Test(expected = IllegalArgumentException.class)
public void genSaltFailsWithTooManyRounds() {
  BCrypt.gensalt(32);
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void genSaltGeneratesCorrectSaltPrefix() {
  assertThat(BCrypt.gensalt(4)).startsWith("$2a$04$");
  assertThat(BCrypt.gensalt(31)).startsWith("$2a$31$");
}

代码示例来源:origin: spring-projects/spring-security

/**
 * Test for correct hashing of non-US-ASCII passwords
 */
@Test
public void testInternationalChars() {
  print("BCrypt.hashpw w/ international chars: ");
  String pw1 = "ππππππππ";
  String pw2 = "????????";
  String h1 = BCrypt.hashpw(pw1, BCrypt.gensalt());
  assertThat(BCrypt.checkpw(pw2, h1)).isFalse();
  print(".");
  String h2 = BCrypt.hashpw(pw2, BCrypt.gensalt());
  assertThat(BCrypt.checkpw(pw1, h2)).isFalse();
  print(".");
  println("");
}

代码示例来源:origin: spring-projects/spring-security

/**
 * Test method for 'BCrypt.gensalt()'
 */
@Test
public void testGensalt() {
  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);
    assertThat(hashed2).isEqualTo(hashed1);
    print(".");
  }
  println("");
}

代码示例来源:origin: spring-projects/spring-security

/**
 * Test method for 'BCrypt.gensalt(int)'
 */
@Test
public void testGensaltInt() {
  print("BCrypt.gensalt(log_rounds):");
  for (int i = 4; i <= 12; i++) {
    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);
      assertThat(hashed2).isEqualTo(hashed1);
      print(".");
    }
  }
  println("");
}

代码示例来源:origin: cloudfoundry/uaa

@Test
public void testSameSaltHash() {
  String salt = BCrypt.gensalt();
  String passwd = "testpassword"+new RandomValueStringGenerator().generate();
  Assert.assertEquals(BCrypt.hashpw(passwd, salt), BCrypt.hashpw(passwd, salt));
}

代码示例来源:origin: org.springframework.security/spring-security-crypto

/**
 * 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: org.springframework.security/org.springframework.security.core

/**
 * 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: org.springframework.security/spring-security-crypto

/**
 * 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. Minimum 4, maximum 31.
 * @return an encoded salt value
 */
public static String gensalt(int log_rounds) {
  return gensalt(log_rounds, new SecureRandom());
}

代码示例来源:origin: PegaSysEng/pantheon

@Override
 public void run() {
  out.print(BCrypt.hashpw(password, BCrypt.gensalt()));
 }
}

相关文章