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

The following examples show how to use org.apache.commons.codec.digest.DigestUtils#sha512Hex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApacheDigester.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
private String encodePassword(CharSequence rawPassword, PasswordSalt passwordSalt) {
    String salt = rawPassword + passwordSalt.getSource().getSalt();
    switch (digester) {
        case MD5:
            return DigestUtils.md5Hex(salt);
        case SHA:
            return DigestUtils.sha1Hex(salt);
        case SHA256:
            return DigestUtils.sha256Hex(salt);
        case SHA348:
            return DigestUtils.sha384Hex(salt);
        case SHA512:
            return DigestUtils.sha512Hex(salt);
    }
    return null;
}
 
Example 2
Source File: PackageStoreAPI.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void validate(List<String> sigs,
                      ByteBuffer buf) throws SolrException, IOException {
  Map<String, byte[]> keys = packageStore.getKeys();
  if (keys == null || keys.isEmpty()) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
        "package store does not have any keys");
  }
  CryptoKeys cryptoKeys = null;
  try {
    cryptoKeys = new CryptoKeys(keys);
  } catch (Exception e) {
    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
        "Error parsing public keys in Package store");
  }
  for (String sig : sigs) {
    if (cryptoKeys.verify(sig, buf) == null) {
      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Signature does not match any public key : " + sig +" len: "+buf.limit()+  " content sha512: "+
          DigestUtils.sha512Hex(new ByteBufferInputStream(buf)));
    }

  }
}
 
Example 3
Source File: TestPackages.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public static void postFileAndWait(MiniSolrCloudCluster cluster, String fname, String path, String sig) throws Exception {
  ByteBuffer fileContent = getFileContent(fname);
  String sha512 = DigestUtils.sha512Hex(fileContent.array());

  TestDistribPackageStore.postFile(cluster.getSolrClient(),
      fileContent,
      path, sig);// has file, but no signature

  TestDistribPackageStore.waitForAllNodesHaveFile(cluster, path, Utils.makeMap(
      ":files:" + path + ":sha512",
      sha512
  ), false);
}
 
Example 4
Source File: InstallAndDownloadTest.java    From pf4j-update with Apache License 2.0 5 votes vote down vote up
public String getSha512() {
    try {
        String checksum = DigestUtils.sha512Hex(Files.newInputStream(updateRepoZipFile));
        log.debug("Generated SHA sum for file: {} ", checksum);
        return checksum;
    } catch (IOException e) {
        return null;
    }
}
 
Example 5
Source File: Sha512SumVerifier.java    From pf4j-update with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies a plugin release according to certain rules
 *
 * @param context the file verifier context object
 * @param file    the path to the downloaded file itself
 * @throws IOException     if there was a problem accessing file
 * @throws VerifyException in case of problems verifying the file
 */
@Override
public void verify(Context context, Path file) throws VerifyException, IOException {
    String expectedSha512sum;
    try {
        if (context.sha512sum == null) {
            log.debug("No sha512 checksum specified, skipping verification");
            return;
        } else if (context.sha512sum.equalsIgnoreCase(".sha512")) {
            String url = context.url.substring(0, context.url.lastIndexOf(".")) + ".sha512";
            expectedSha512sum = getUrlContents(url).split(" ")[0].trim();
        } else if (context.sha512sum.startsWith("http")) {
            expectedSha512sum = getUrlContents(context.sha512sum).split(" ")[0].trim();
        } else {
            expectedSha512sum = context.sha512sum;
        }
    } catch (IOException e) {
        throw new VerifyException(e, "SHA512 checksum verification failed, could not download SHA512 file ({})", context.sha512sum);
    }

    log.debug("Verifying sha512 checksum of file {}", file.getFileName());
    String actualSha512sum = DigestUtils.sha512Hex(Files.newInputStream(file));
    if (actualSha512sum.equalsIgnoreCase(expectedSha512sum)) {
        log.debug("Checksum OK");
        return;
    }
    throw new VerifyException("SHA512 checksum of downloaded file " + file.getFileName()
            + " does not match that from plugin descriptor. Got " + actualSha512sum
            + " but expected " + expectedSha512sum);
}
 
Example 6
Source File: EditingSessionManager.java    From apicurio-studio with Apache License 2.0 5 votes vote down vote up
/**
 * @see io.apicurio.hub.core.editing.IEditingSessionManager#createSessionUuid(java.lang.String, java.lang.String, java.lang.String, long)
 */
@Override
public String createSessionUuid(String designId, String user, String secret, long contentVersion) throws ServerError {
    try {
        UUID uuid = UUID.randomUUID();
        String hash = DigestUtils.sha512Hex(SALT + user + secret);
        long expiresOn = System.currentTimeMillis() + EXPIRATION_OFFSET;
        this.storage.createEditingSessionUuid(uuid.toString(), designId, user, hash, contentVersion, expiresOn);
        return uuid.toString();
    } catch (StorageException e) {
        throw new ServerError(e);
    }
}
 
Example 7
Source File: PackageStoreAPI.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a JSON string with the metadata
 * @lucene.internal
 */
public static MetaData _createJsonMetaData(ByteBuffer buf, List<String> signatures) throws IOException {
  String sha512 = DigestUtils.sha512Hex(new ByteBufferInputStream(buf));
  Map<String, Object> vals = new HashMap<>();
  vals.put(MetaData.SHA512, sha512);
  if (signatures != null) {
    vals.put("sig", signatures);
  }
  return new MetaData(vals);
}
 
Example 8
Source File: Sha512Hash.java    From text_converter with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public String encode(@NonNull String text) {
    try {
        return DigestUtils.sha512Hex(text.getBytes());
    } catch (Exception e) {
        return "";
    }
}
 
Example 9
Source File: CodecUtils.java    From juice with Apache License 2.0 4 votes vote down vote up
public static String sha512Hex(final InputStream in) throws IOException {
    return DigestUtils.sha512Hex(in);
}
 
Example 10
Source File: CodecUtils.java    From juice with Apache License 2.0 4 votes vote down vote up
public static String sha512Hex(final byte[] data) {
    return DigestUtils.sha512Hex(data);
}
 
Example 11
Source File: CodecUtils.java    From leyou with Apache License 2.0 4 votes vote down vote up
public static String shaHex(String data, String salt) {
    if (StringUtils.isBlank(salt)) {
        salt = data.hashCode() + "";
    }
    return DigestUtils.sha512Hex(salt + DigestUtils.sha512Hex(data));
}
 
Example 12
Source File: AuthService.java    From elasticsearch-auth with Apache License 2.0 4 votes vote down vote up
private String generateToken() {
    return DigestUtils.sha512Hex(UUID.randomUUID().toString());
}
 
Example 13
Source File: AnonymizeProcessor.java    From sawmill with Apache License 2.0 4 votes vote down vote up
@Override
public String anonimize(String value) {
    return DigestUtils.sha512Hex(value);
}
 
Example 14
Source File: CodecUtils.java    From juice with Apache License 2.0 4 votes vote down vote up
public static String sha512Hex(final String data) {
    return DigestUtils.sha512Hex(data);
}
 
Example 15
Source File: IndexAuthenticator.java    From elasticsearch-auth with Apache License 2.0 4 votes vote down vote up
protected String getUserId(final String username) {
    return DigestUtils.sha512Hex(username);
}
 
Example 16
Source File: CodecUtil.java    From common_gui_tools with Apache License 2.0 3 votes vote down vote up
/**
 * Calculates the SHA-512 digest and returns the value as a hex string.
 *
 * @param string  String
 * @param charSet CharSet
 * @return <code>String</code> SHA-512 string
 * @throws UnsupportedEncodingException unsupported encoding exception
 */
public static String encryptSha512(String string, String charSet) throws UnsupportedEncodingException {
    if (string == null) {
        return null;
    }
    return DigestUtils.sha512Hex(string.getBytes(charSet));
}
 
Example 17
Source File: CodecUtils.java    From mangooio with Apache License 2.0 3 votes vote down vote up
/**
 * Hashes a given cleartext data with SHA512 and an appended salt
 * 
 * @param data The cleartext data
 * @param salt The salt to use
 * @return SHA512 hashed value
 */
public static String hexSHA512(String data, String salt) {
    Objects.requireNonNull(data, Required.DATA.toString());
    Objects.requireNonNull(salt, Required.SALT.toString());
    
    return DigestUtils.sha512Hex(data + salt);
}
 
Example 18
Source File: CodecUtils.java    From mangooio with Apache License 2.0 2 votes vote down vote up
/**
 * Hashes a given cleartext data with SHA512
 * 
 * @param data The cleartext data
 * @return SHA512 hashed value
 */
public static String hexSHA512(String data) {
    Objects.requireNonNull(data, Required.DATA.toString());
    
    return DigestUtils.sha512Hex(data);
}
 
Example 19
Source File: CryptoUtils.java    From zheshiyigeniubidexiangmu with MIT License 2 votes vote down vote up
/**
 * SHA加密
 *
 * @param bytes
 *            an array of byte.
 * @return a {@link java.lang.String} object.
 */
public static String encodeSHA(final byte[] bytes) {
    return DigestUtils.sha512Hex(bytes);
}
 
Example 20
Source File: CryptoUtils.java    From common-mvc with MIT License 2 votes vote down vote up
/**
 * SHA加密
 *
 * @param bytes
 *            an array of byte.
 * @return a {@link String} object.
 */
public static String encodeSHA(final byte[] bytes) {
    return DigestUtils.sha512Hex(bytes);
}