本文整理汇总了Java中org.apache.shiro.crypto.hash.HashRequest.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java HashRequest.Builder方法的具体用法?Java HashRequest.Builder怎么用?Java HashRequest.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.shiro.crypto.hash.HashRequest
的用法示例。
在下文中一共展示了HashRequest.Builder方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calculateHash
import org.apache.shiro.crypto.hash.HashRequest; //导入方法依赖的package包/类
private static Hash calculateHash(String password) {
ByteSource privateSalt = ByteSource.Util.bytes(PRIVATE_SALT_BYTES);
DefaultHashService hashService = new DefaultHashService();
hashService.setPrivateSalt(privateSalt);
hashService.setGeneratePublicSalt(true);
hashService.setHashIterations(ITERATIONS);
HashRequest.Builder builder = new HashRequest.Builder();
builder.setSource(ByteSource.Util.bytes(password));
Hash hash = hashService.computeHash(builder.build());
log.info("Hash algorithm {}, iterations {}, public salt {}", hash.getAlgorithmName(), hash.getIterations(), hash.getSalt());
return hash;
}
示例2: verifyPassword
import org.apache.shiro.crypto.hash.HashRequest; //导入方法依赖的package包/类
private static boolean verifyPassword(byte[] originalHash, ByteSource publicSalt, String password) {
ByteSource privateSalt = ByteSource.Util.bytes(PRIVATE_SALT_BYTES);
DefaultHashService hashService = new DefaultHashService();
hashService.setPrivateSalt(privateSalt);
hashService.setHashIterations(ITERATIONS);
HashRequest.Builder builder = new HashRequest.Builder();
builder.setSource(ByteSource.Util.bytes(password));
builder.setSalt(publicSalt);
Hash comparisonHash = hashService.computeHash(builder.build());
log.info("password: {}", password);
log.info("1 hash: {}", Hex.encodeToString(originalHash));
log.info("2 hash: {}", comparisonHash.toHex());
return Arrays.equals(originalHash, comparisonHash.getBytes());
}
示例3: createAuthenticationInfo
import org.apache.shiro.crypto.hash.HashRequest; //导入方法依赖的package包/类
@Override
protected AuthenticationInfo createAuthenticationInfo(AuthenticationToken token,
Object ldapPrincipal,
Object ldapCredentials, LdapContext ldapContext) throws NamingException {
HashRequest.Builder builder = new HashRequest.Builder();
Hash credentialsHash = hashService
.computeHash(builder.setSource(token.getCredentials())
.setAlgorithmName(HASHING_ALGORITHM).build());
return new SimpleAuthenticationInfo(token.getPrincipal(),
credentialsHash.toHex(), credentialsHash.getSalt(),
getName());
}