当前位置: 首页>>代码示例>>Java>>正文


Java RandomNumberGenerator.nextBytes方法代码示例

本文整理汇总了Java中org.apache.shiro.crypto.RandomNumberGenerator.nextBytes方法的典型用法代码示例。如果您正苦于以下问题:Java RandomNumberGenerator.nextBytes方法的具体用法?Java RandomNumberGenerator.nextBytes怎么用?Java RandomNumberGenerator.nextBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.shiro.crypto.RandomNumberGenerator的用法示例。


在下文中一共展示了RandomNumberGenerator.nextBytes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: securePassword

import org.apache.shiro.crypto.RandomNumberGenerator; //导入方法依赖的package包/类
/**
 * Шифрует пароль в профиле пользователя. Предпологаетя, что пароль
 * находится в <code>user.getPassword()</code> в открытом виде.
 *
 * @param user профиль пользователя
 */
public static void securePassword(final UserProfile user) {
    // We'll use a Random Number Generator to generate salts. This is
    // much more secure than using a username as a salt or nothaving a
    // salt at all. Shiro makes this easy.
    // Note that a normal app would reference an attribute rather than
    // create a new RNG every time:
    final RandomNumberGenerator rng = new SecureRandomNumberGenerator();
    final ByteSource salt = rng.nextBytes();

    final String plainTextPassword = user.getPassword();
    // Now hash the plain-text password with the random salt and
    // multiple
    // iterations and then Base64-encode the value (requires less space
    // than Hex):
    final String hashedPasswordBase64 = new Sha256Hash(plainTextPassword, salt, HASH_ITERATIONS).toBase64();

    // saveAndChangeOwner the salt with the new account. The HashedCredentialsMatcher
    // will need it later when handling login attempts:
    user.setPasswordSalt(salt.toBase64());
    user.setPassword(hashedPasswordBase64);
}
 
开发者ID:ExtaSoft,项目名称:extacrm,代码行数:28,代码来源:UserRealm.java

示例2: generatePassword

import org.apache.shiro.crypto.RandomNumberGenerator; //导入方法依赖的package包/类
private void generatePassword(User user, String plainTextPassword) {
    RandomNumberGenerator rng = new SecureRandomNumberGenerator();
    Object salt = rng.nextBytes();
    String hashedPasswordBase64 = new Sha256Hash(plainTextPassword, salt, 1024).toBase64();
    user.setPassword(hashedPasswordBase64);
    user.setSalt(salt.toString());
}
 
开发者ID:ETspielberg,项目名称:bibliometrics,代码行数:8,代码来源:BibliometricReportExportServlet.java

示例3: generatePassword

import org.apache.shiro.crypto.RandomNumberGenerator; //导入方法依赖的package包/类
private void generatePassword(User user, String plainTextPassword) {
  RandomNumberGenerator rng = new SecureRandomNumberGenerator();
  Object salt = rng.nextBytes();
  String hashedPasswordBase64 = new Sha256Hash(plainTextPassword, salt,1024).toBase64();
  user.setPassword(hashedPasswordBase64);
  user.setSalt(salt.toString());
}
 
开发者ID:ETspielberg,项目名称:bibliometrics,代码行数:8,代码来源:UserRegistrationServlet.java

示例4: HashedBase64Password

import org.apache.shiro.crypto.RandomNumberGenerator; //导入方法依赖的package包/类
public HashedBase64Password(String password, RandomNumberGenerator rng) {
    ByteSource salt = rng.nextBytes();
    HashedCredentialsMatcher matcher = ((HashedCredentialsMatcher) GwtUtilRealm.this.getCredentialsMatcher());
    this.password = new SimpleHash(matcher.getHashAlgorithmName(), password, salt, matcher.getHashIterations()).toBase64();
    this.salt = salt.toBase64();
}
 
开发者ID:rkfg,项目名称:gwtutil,代码行数:7,代码来源:GwtUtilRealm.java

示例5: getSaltAndHash

import org.apache.shiro.crypto.RandomNumberGenerator; //导入方法依赖的package包/类
public Pair<List<Byte>, String> getSaltAndHash(final String plainTextPassword) {
    RandomNumberGenerator rng = new SecureRandomNumberGenerator();
    final ByteSource salt = rng.nextBytes();
    final String hashedPasswordBase64 = new Sha256Hash(plainTextPassword, salt, HASH_ITERATION).toBase64();
    return new ImmutablePair<List<Byte>, String>(toBytes(salt), hashedPasswordBase64);
}
 
开发者ID:ageldama,项目名称:glados-wiki,代码行数:7,代码来源:Sha256.java


注:本文中的org.apache.shiro.crypto.RandomNumberGenerator.nextBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。