Java Digest digest(String raw, String algorithm)

Here you can find the source of digest(String raw, String algorithm)

Description

digest

License

Open Source License

Declaration

private static String digest(String raw, String algorithm) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    private static String digest(String raw, String algorithm) {
        if (raw == null || "".equals(raw))
            return "";
        MessageDigest md;/* w  w w  .  j  a  v a 2 s.  co  m*/
        try {
            md = MessageDigest.getInstance(algorithm);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        md.update(raw.getBytes());
        StringBuilder sb = new StringBuilder();
        for (byte b : md.digest()) {
            String hex = String.format("%02x", b);
            sb.append(hex);
        }
        return sb.toString();
    }
}

Related

  1. digest(String orgin, String algorithm)
  2. digest(String password)
  3. digest(String plain, String algorithm)
  4. digest(String planeText)
  5. digest(String provider, File file, int radix)
  6. digest(String s, String algorithm)
  7. digest(String source)
  8. digest(String source, byte[] salt)
  9. digest(String source, String algorythm)