org.apache.shiro.crypto.hash.Hash.toHex()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(241)

本文整理了Java中org.apache.shiro.crypto.hash.Hash.toHex()方法的一些代码示例,展示了Hash.toHex()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hash.toHex()方法的具体详情如下:
包路径:org.apache.shiro.crypto.hash.Hash
类名称:Hash
方法名:toHex

Hash.toHex介绍

暂无

代码示例

代码示例来源:origin: apache/shiro

/**
   * Returns {@code hash != null ? hash.toHex() : null}.
   *
   * @param hash the hash instance to format into a String.
   * @return {@code hash != null ? hash.toHex() : null}.
   */
  public String format(Hash hash) {
    return hash != null ? hash.toHex() : null;
  }
}

代码示例来源:origin: apache/shiro

String hashed = hex ? hash.toHex() : hash.toBase64();
System.out.print(hex ? "Hex: " : "Base64: ");
System.out.println(hashed);

代码示例来源:origin: org.apache.shiro/shiro-crypto-hash

/**
   * Returns {@code hash != null ? hash.toHex() : null}.
   *
   * @param hash the hash instance to format into a String.
   * @return {@code hash != null ? hash.toHex() : null}.
   */
  public String format(Hash hash) {
    return hash != null ? hash.toHex() : null;
  }
}

代码示例来源:origin: xiaolongzuo/niubi-job

public static String getHashedPassword(String password, String salt) {
  Hash hash = new SimpleHash(hashAlgorithm, password, salt);
  return hash.toHex();
}

代码示例来源:origin: org.apache.shiro/shiro-crypto-hash

String hashed = hex ? hash.toHex() : hash.toBase64();
System.out.print(hex ? "Hex: " : "Base64: ");
System.out.println(hashed);

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.shiro

String hashed = hex ? hash.toHex() : hash.toBase64();
System.out.print(hex ? "Hex: " : "Base64: ");
System.out.println(hashed);

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.shiro

String hashed = hex ? hash.toHex() : hash.toBase64();
System.out.print(hex ? "Hex: " : "Base64: ");
System.out.println(hashed);

代码示例来源:origin: org.jasig.cas/cas-server-support-jdbc

/**
 * Digest encoded password.
 *
 * @param encodedPassword the encoded password
 * @param values the values retrieved from database
 * @return the digested password
 */
protected String digestEncodedPassword(final String encodedPassword, final Map<String, Object> values) {
  final ConfigurableHashService hashService = new DefaultHashService();
  if (StringUtils.isNotBlank(this.staticSalt)) {
    hashService.setPrivateSalt(ByteSource.Util.bytes(this.staticSalt));
  }
  hashService.setHashAlgorithmName(this.algorithmName);
  Long numOfIterations = this.numberOfIterations;
  if (values.containsKey(this.numberOfIterationsFieldName)) {
    final String longAsStr = values.get(this.numberOfIterationsFieldName).toString();
    numOfIterations = Long.valueOf(longAsStr);
  }
  hashService.setHashIterations(numOfIterations.intValue());
  if (!values.containsKey(this.saltFieldName)) {
    throw new RuntimeException("Specified field name for salt does not exist in the results");
  }
  final String dynaSalt = values.get(this.saltFieldName).toString();
  final HashRequest request = new HashRequest.Builder()
                .setSalt(dynaSalt)
                .setSource(encodedPassword)
                .build();
  return hashService.computeHash(request).toHex();
}

代码示例来源:origin: net.unicon.cas/cas-addons

@Override
public String encode(String password) {
  if (password == null) {
    return null;
  }
  return this.hashService.computeHash(new HashRequest.Builder().setSalt(this.salt).setSource(password).build()).toHex();
}

代码示例来源:origin: dschadow/JavaSecurity

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());
  }
}

代码示例来源:origin: org.apache.knox/gateway-provider-security-shiro

@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());
}

代码示例来源:origin: apache/knox

@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());
}

代码示例来源:origin: org.apache.knox/gateway-provider-security-shiro

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
 UsernamePasswordToken upToken = (UsernamePasswordToken) token;
 UnixUser user = null;
 try {
  user = (new PAM(this.getService())).authenticate(upToken.getUsername(), new String(upToken.getPassword()));
 } catch (PAMException e) {
  handleAuthFailure(token, e.getMessage(), e);
 }
 HashRequest.Builder builder = new HashRequest.Builder();
 Hash credentialsHash = hashService
   .computeHash(builder.setSource(token.getCredentials()).setAlgorithmName(HASHING_ALGORITHM).build());
 /* Coverity Scan CID 1361684 */
 if (credentialsHash == null) {
  handleAuthFailure(token, "Failed to compute hash", null);
 }
 return new SimpleAuthenticationInfo(new UnixUserPrincipal(user), credentialsHash.toHex(), credentialsHash.getSalt(),
   getName());
}

代码示例来源:origin: apache/knox

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
 UsernamePasswordToken upToken = (UsernamePasswordToken) token;
 UnixUser user = null;
 try {
  user = (new PAM(this.getService())).authenticate(upToken.getUsername(), new String(upToken.getPassword()));
 } catch (PAMException e) {
  handleAuthFailure(token, e.getMessage(), e);
 }
 HashRequest.Builder builder = new HashRequest.Builder();
 Hash credentialsHash = hashService
   .computeHash(builder.setSource(token.getCredentials()).setAlgorithmName(HASHING_ALGORITHM).build());
 /* Coverity Scan CID 1361684 */
 if (credentialsHash == null) {
  handleAuthFailure(token, "Failed to compute hash", null);
 }
 return new SimpleAuthenticationInfo(new UnixUserPrincipal(user), credentialsHash.toHex(), credentialsHash.getSalt(),
   getName());
}

相关文章