Java Code Examples for org.apache.commons.codec.digest.DigestUtils.sha512Hex()

The following are Jave code examples for showing how to use sha512Hex() of the org.apache.commons.codec.digest.DigestUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: webcron   File: HashUtils.java   View Source Code Vote up 7 votes
/**
 * @param message {@link String}
 * @param type    {@link HashType}
 * @return {@link String}
 */
private static String sha(String message, HashType type) {
    switch (type) {
        case SHA1:
            return DigestUtils.sha1Hex(message);
        case SHA256:
            return DigestUtils.sha256Hex(message);
        case SHA512:
            return DigestUtils.sha512Hex(message);
        default:
            return DigestUtils.sha256Hex(message);
    }
}
 
Example 2
Project: hygene   File: FileMetadata.java   View Source Code Vote up 6 votes
/**
 * Computes the digest of the contents of the file this database belongs to.
 *
 * @return a digest, representing the contents of the file
 * @throws IOException in the case of an error during IO operations
 */
private String computeFileDigest() throws IOException {
    final BasicFileAttributes attr =
            Files.readAttributes(Paths.get(fileDatabase.getFileName()), BasicFileAttributes.class);

    return DigestUtils.sha512Hex(fileDatabase.getFileName() + attr.lastModifiedTime() + attr.size());
}
 
Example 3
Project: minlia-iot   File: XmlSignatureAnnotationHelper.java   View Source Code Vote up 6 votes
/**
 * 根据SinpleField列表生成签名
 *
 * 加2个参数   delimiter,caseConvert
 *
 * @param fieldPaireds SinpleField的列表
 * @param salt partnerApiKey
 * @return 生成的签名字符串
 */
private static String makeSignBySinpleFieldList(List<FieldPaired> fieldPaireds, String salt,
    Boolean excludeKeyParameter, SignatureAlgorithmic algorithmic, String saltParameterPrefix,
    String charset, CaseControl caseControl, String delimiter) {
  List<String> list = fieldPaireds.stream()
      .sorted(new AsciiSortedComparator<>(FieldPaired::getProperty)).map(
          FieldPaired::toString).collect(Collectors.toList());

  //在对象上添加特殊属性, 当不排除时添加
  if (!excludeKeyParameter) {
    if (StringUtils.isEmpty(saltParameterPrefix)) {
      throw new RuntimeException("指定了需要添加KEY=到salt前面, 却没有指定前前缀, 请检查官方文档,再做相应调整");
    }
    list.add(saltParameterPrefix + salt);
  }

  // 未加密字符串
  String unencrypted = "";
  try {
    unencrypted = new String(String.join(delimiter, list).getBytes(), charset);
    //将salt添加到最后面
    if (!StringUtils.isEmpty(salt)) {
      if (excludeKeyParameter) {
        unencrypted += salt;
      }
    }
    log.debug("Unencrypted String is: {}", unencrypted);
  } catch (Exception e) {
    e.printStackTrace();
  }

  String result = "";
  switch (algorithmic) {
    case MD2:
      result = DigestUtils.md2Hex(unencrypted);
      break;
    case MD5:
      result = DigestUtils.md5Hex(unencrypted);
      break;
    case SHA1:
      result = DigestUtils.sha1Hex(unencrypted);
      break;
    case SHA256:
      result = DigestUtils.sha256Hex(unencrypted);
      break;
    case SHA384:
      result = DigestUtils.sha384Hex(unencrypted);
      break;
    case SHA512:
      result = DigestUtils.sha512Hex(unencrypted);
      break;
    default:
      throw new RuntimeException("不支持的签名类型");
  }

  if (null != caseControl) {
    switch (caseControl) {
      case TO_LOWER_CASE:
        result = result.toLowerCase();
        break;
      case TO_UPPER_CASE:
        result = result.toUpperCase();
        break;
    }
  }

  log.debug("Encrypted Signature is: {}", result);
  return result;

}
 
Example 4
Project: citizensLoader4a   File: Citizen.java   View Source Code Vote up 4 votes
public Citizen(String nombre, String apellidos, String email, Date fecha_nacimiento, String direccion_postal,
			   String nacionalidad, String numero_identificativo, String contrasena) {
	this(nombre,apellidos,email,fecha_nacimiento,direccion_postal,nacionalidad,numero_identificativo);
	this.contrasena= DigestUtils.sha512Hex(contrasena);
	this.contrasena_NC=contrasena;
}
 
Example 5
Project: citizensLoader4a   File: Citizen.java   View Source Code Vote up 4 votes
public void setContrasena(String password) {
	this.contrasena= DigestUtils.sha512Hex(password);
	this.contrasena_NC=password;
}
 
Example 6
Project: pac4j-plus   File: BasicSaltedSha512PasswordEncoder.java   View Source Code Vote up 4 votes
@Override
public String encode(final String password) {
    CommonHelper.assertNotBlank("salt", salt);

    return DigestUtils.sha512Hex(password + salt);
}
 
Example 7
Project: sierra   File: Sequence.java   View Source Code Vote up 4 votes
public String getSHA512() {
	return DigestUtils.sha512Hex(sequence);
}
 
Example 8
Project: springboot-shiro-cas-mybatis   File: CompressionUtils.java   View Source Code Vote up 2 votes
/**
 * Calculates the SHA-512 digest and returns the value as a hex string.
 *
 * @param input the input
 * @return the value as hex
 * @since 4.2
 */
public static String sha512Hex(final String input) {
    return DigestUtils.sha512Hex(input);
}
 
Example 9
Project: nectar-server   File: Util.java   View Source Code Vote up 2 votes
/**
 * Compute the SHA-512 Hash of a String.
 * @param plaintext The raw text to be hashed.
 * @return The has of the provided text.
 */
public static String computeSHA512(String plaintext) {
    return DigestUtils.sha512Hex(plaintext);
}
 
Example 10
Project: cas-server-4.2.1   File: CompressionUtils.java   View Source Code Vote up 2 votes
/**
 * Calculates the SHA-512 digest and returns the value as a hex string.
 *
 * @param input the input
 * @return the value as hex
 * @since 4.2
 */
public static String sha512Hex(final String input) {
    return DigestUtils.sha512Hex(input);
}