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


Java RandomNumberGenerator类代码示例

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


RandomNumberGenerator类属于org.apache.shiro.crypto包,在下文中一共展示了RandomNumberGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: bind

import org.apache.shiro.crypto.RandomNumberGenerator; //导入依赖的package包/类
public static void bind(ServiceBinder binder) {
    binder.bind(RandomNumberGenerator.class, SecureRandomNumberGenerator.class);
    binder.bind(ConfigurationService.class, ConfigurationServiceImpl.class);
    binder.bind(VdrDataService.class, VdrDataServiceImpl.class);
    binder.bind(EpgDataService.class, EpgDataServiceFacadeImpl.class);
    binder.bind(EpgImageService.class, EpgImageServiceFacadeImpl.class);
    binder.bind(CommandService.class, CommandServiceImpl.class);
    binder.bind(EpgdSearchTimerService.class, EpgdSearchTimerServiceImpl.class);
    binder.bind(SvdrpNashornService.class, SvdrpNashornServiceImpl.class);
    binder.bind(Epg2VdrNashornService.class, Epg2VdrNashornServiceImpl.class);
    binder.bind(ChannelMapService.class, ChannelMapServiceImpl.class);
    binder.bind(UserService.class, UserServiceImpl.class);
    binder.bind(ChannelEncoder.class);
    binder.bind(GlobalLogoFilename.class);
    binder.bind(GlobalValues.class);
}
 
开发者ID:Zabrimus,项目名称:vdr-jonglisto,代码行数:17,代码来源:AppModule.java

示例3: register

import org.apache.shiro.crypto.RandomNumberGenerator; //导入依赖的package包/类
@Override
public Long register(final String username, final String password, final RandomNumberGenerator rng) throws GwtUtilException {
    return HibernateUtil.exec(session -> {
        HashedBase64Password base64Password = new HashedBase64Password(password, rng);
        User user = (User) session.createQuery("from User where username = :username").setParameter("username", username)
                .setMaxResults(1).uniqueResult();
        if (user == null) {
            user = new User(username, base64Password.getPassword());
        } else {
            // change password for existing user
            user.setPassword(base64Password.getPassword());
        }
        // save the salt with the new account. The
        // HashedCredentialsMatcher
        // will need it later when handling login attempts:
        user.setSalt(base64Password.getSalt());
        user = (User) session.merge(user);
        return user.getId();
    });
}
 
开发者ID:rkfg,项目名称:gwtutil,代码行数:21,代码来源:HibernateRealm.java

示例4: 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

示例5: 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

示例6: encryptPassword

import org.apache.shiro.crypto.RandomNumberGenerator; //导入依赖的package包/类
@Override
public void encryptPassword(SysUser user) {
    RandomNumberGenerator randomNumberGenerator = new SecureRandomNumberGenerator();
    user.setSalt(randomNumberGenerator.nextBytes().toHex());
    String password = new SimpleHash(algorithmName, user.getPassword(),
            ByteSource.Util.bytes(user.getUsername() + user.getSalt()),
            hashIterations).toHex();
    user.setPassword(password);
}
 
开发者ID:edgar615,项目名称:javase-study,代码行数:10,代码来源:MD51024ServiceImpl.java

示例7: createToken

import org.apache.shiro.crypto.RandomNumberGenerator; //导入依赖的package包/类
/**
 * 生成随机的TOKEN
 *
 * @param key       键
 * @param expiresIn 有效时间
 * @return token
 */
private String createToken(String key, long expiresIn) {
    StringBuilder token = new StringBuilder(key);
    RandomNumberGenerator randomNumberGenerator = new SecureRandomNumberGenerator();
    String salt = randomNumberGenerator.nextBytes().toHex();
    token.append(salt);
    token.append(System.currentTimeMillis() + expiresIn);
    return new SimpleHash(Constants.TOKEN_ALGORITHM_NAME, key, ByteSource.Util.bytes(token.toString()), Constants.TOKEN_HASH_ITERATIONS).toHex();
}
 
开发者ID:edgar615,项目名称:javase-study,代码行数:16,代码来源:AuthServiceImpl.java

示例8: register

import org.apache.shiro.crypto.RandomNumberGenerator; //导入依赖的package包/类
@Override
public Long register(String username, String password, RandomNumberGenerator rng) throws GwtUtilException {
    HashedBase64Password base64Password = new HashedBase64Password(password, rng);
    UserDTO user = new UserDTO();
    user.setId(++id);
    user.setUsername(username);
    user.setPassword(base64Password.getPassword());
    user.setSalt(base64Password.getSalt());
    users.put(username, user);
    roles.put(username, new HashSet<>());
    return user.getId();
}
 
开发者ID:rkfg,项目名称:gwtutil,代码行数:13,代码来源:InMemoryRealm.java

示例9: setRandomNumberGenerator

import org.apache.shiro.crypto.RandomNumberGenerator; //导入依赖的package包/类
public void setRandomNumberGenerator(RandomNumberGenerator randomNumberGenerator) {
    this.randomNumberGenerator = randomNumberGenerator;
}
 
开发者ID:melonlee,项目名称:LazyREST,代码行数:4,代码来源:PasswordUtil.java

示例10: setRandomNumberGenerator

import org.apache.shiro.crypto.RandomNumberGenerator; //导入依赖的package包/类
public void setRandomNumberGenerator(RandomNumberGenerator rng) {
    this.rng = rng;
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:4,代码来源:DefaultHashService.java

示例11: getRandomNumberGenerator

import org.apache.shiro.crypto.RandomNumberGenerator; //导入依赖的package包/类
public RandomNumberGenerator getRandomNumberGenerator() {
    return this.rng;
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:4,代码来源:DefaultHashService.java

示例12: UserServiceImpl

import org.apache.shiro.crypto.RandomNumberGenerator; //导入依赖的package包/类
public UserServiceImpl(RandomNumberGenerator randomNumber) {
    this.randomNumber = randomNumber;
}
 
开发者ID:Zabrimus,项目名称:vdr-jonglisto,代码行数:4,代码来源:UserServiceImpl.java

示例13: setRandomNumberGenerator

import org.apache.shiro.crypto.RandomNumberGenerator; //导入依赖的package包/类
public void setRandomNumberGenerator(final RandomNumberGenerator randomNumberGenerator) {
    this.randomNumberGenerator = randomNumberGenerator;
}
 
开发者ID:xianrendzw,项目名称:EasyReport,代码行数:4,代码来源:ShiroPasswordService.java

示例14: setRandomNumberGenerator

import org.apache.shiro.crypto.RandomNumberGenerator; //导入依赖的package包/类
public void setRandomNumberGenerator(RandomNumberGenerator randomNumberGenerator) {
	this.randomNumberGenerator = randomNumberGenerator;
}
 
开发者ID:colddew,项目名称:mix-web,代码行数:4,代码来源:PasswordUtils.java

示例15: 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


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