本文整理汇总了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);
}
示例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);
}
示例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();
});
}
示例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());
}
示例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());
}
示例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);
}
示例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();
}
示例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();
}
示例9: setRandomNumberGenerator
import org.apache.shiro.crypto.RandomNumberGenerator; //导入依赖的package包/类
public void setRandomNumberGenerator(RandomNumberGenerator randomNumberGenerator) {
this.randomNumberGenerator = randomNumberGenerator;
}
示例10: setRandomNumberGenerator
import org.apache.shiro.crypto.RandomNumberGenerator; //导入依赖的package包/类
public void setRandomNumberGenerator(RandomNumberGenerator rng) {
this.rng = rng;
}
示例11: getRandomNumberGenerator
import org.apache.shiro.crypto.RandomNumberGenerator; //导入依赖的package包/类
public RandomNumberGenerator getRandomNumberGenerator() {
return this.rng;
}
示例12: UserServiceImpl
import org.apache.shiro.crypto.RandomNumberGenerator; //导入依赖的package包/类
public UserServiceImpl(RandomNumberGenerator randomNumber) {
this.randomNumber = randomNumber;
}
示例13: setRandomNumberGenerator
import org.apache.shiro.crypto.RandomNumberGenerator; //导入依赖的package包/类
public void setRandomNumberGenerator(final RandomNumberGenerator randomNumberGenerator) {
this.randomNumberGenerator = randomNumberGenerator;
}
示例14: setRandomNumberGenerator
import org.apache.shiro.crypto.RandomNumberGenerator; //导入依赖的package包/类
public void setRandomNumberGenerator(RandomNumberGenerator randomNumberGenerator) {
this.randomNumberGenerator = randomNumberGenerator;
}
示例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();
}