Java Utililty Methods Digest

List of utility methods to do Digest

Description

The list of methods to do Digest are organized into topic(s).

Method

StringdigestHmacToBase64(String algorithm, String msg, byte[] privateKey)
Firma un mensaje y devuelve la firma en formato string base 64
Mac mac = Mac.getInstance(algorithm);
SecretKeySpec key = new SecretKeySpec(privateKey, algorithm);
mac.init(key);
byte[] macBytes = mac.doFinal(msg.getBytes("UTF-8"));
return Base64.getEncoder().encodeToString(macBytes);
MessageDigestdigestInit()
digest Init
return digestInit(MD5);
byte[]digestOperation(String algo, byte[]... content)
digest Operation
try {
    MessageDigest messagedigest = MessageDigest.getInstance(algo);
    for (byte[] data : content) {
        messagedigest.update(data);
    return messagedigest.digest();
} catch (NoSuchAlgorithmException nosuchalgorithmexception) {
    nosuchalgorithmexception.printStackTrace();
...
byte[]digestStream(MessageDigest digest, InputStream is)
digest Stream
byte[] buf = new byte[4096];
int nRead;
while ((nRead = is.read(buf)) != -1) {
    digest.update(buf, 0, nRead);
return digest.digest();
voiddigestString(MessageDigest md, String s)
Utility method to digest String s.
int len = s.length();
byte[] b = new byte[len];
for (int i = 0; i < len; i++) {
    char c = s.charAt(i);
    if (c < 127) {
        b[i] = (byte) c;
    } else {
        b[i] = '?';
...
StringdigestString(String input)
Creates an MD5 hash of the input string.
String digested = "";
try {
    MessageDigest md = MessageDigest.getInstance("MD5");
    byte[] res = md.digest(input.getBytes());
    StringBuilder sb = new StringBuilder();
    for (byte b1 : res) {
        sb.append(Integer.toHexString(0xFF & b1));
    digested = sb.toString();
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
} finally {
    return digested;
StringdigestString(String pass, String algorithm)
digest String
MessageDigest md;
ByteArrayOutputStream bos;
md = MessageDigest.getInstance(algorithm);
byte[] digest = md.digest(pass.getBytes());
return new String(digest);
StringdigestString(String pass, String algorithm)
Calculate digest of given String using given algorithm.
MessageDigest md;
ByteArrayOutputStream bos;
try {
    md = MessageDigest.getInstance(algorithm);
    byte[] digest = md.digest(pass.getBytes("iso-8859-1"));
    bos = new ByteArrayOutputStream();
    OutputStream encodedStream = MimeUtility.encode(bos, "base64");
    encodedStream.write(digest);
...
StringdigestThenEncodePasswordForLDAP(String algorithm, String credentials)
digest Then Encode Password For LDAP
String hashedCredentials = credentials;
if ((credentials != null) && (credentials.length() > 0)) {
    boolean isMD5Hash = algorithm.equalsIgnoreCase("MD5");
    boolean isSHAHash = algorithm.equalsIgnoreCase("SHA") || algorithm.equalsIgnoreCase("SHA1")
            || algorithm.equalsIgnoreCase("SHA-1");
    if (isSHAHash || isMD5Hash) {
        String hashAlgorithm = "MD5";
        if (isSHAHash) {
...
byte[]digestWithSalt(String password, byte[] salt, String algorithm)
digest With Salt
try {
    MessageDigest md = MessageDigest.getInstance(algorithm);
    md.update(password.getBytes("UTF-8"));
    md.update(salt);
    return md.digest();
} catch (NoSuchAlgorithmException e) {
    throw new RuntimeException(algorithm, e);
} catch (UnsupportedEncodingException e) {
...