本文整理汇总了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);
}
示例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());
}
示例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());
}
示例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();
}
示例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);
}