Java SHA1 sha1Utf8(String clearText)

Here you can find the source of sha1Utf8(String clearText)

Description

sha Utf

License

Open Source License

Declaration

public static String sha1Utf8(String clearText) 

Method Source Code

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

import java.nio.charset.Charset;
import java.security.MessageDigest;

public class Main {
    public static String sha1Utf8(String clearText) {
        StringBuilder sb = new StringBuilder();
        try {//from   w  ww  . j  a v a2  s.c o  m
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            md.update(clearText.getBytes(Charset.forName("UTF-8")));
            byte[] md5 = md.digest();
            for (byte b : md5) {
                int i = (b & 0xff);
                if (i < 16)
                    sb.append("0");
                sb.append(Integer.toHexString(i).toUpperCase());
            }
        } catch (Exception e) {
            return "Can't sha1, exception " + e.getMessage();
        }
        return sb.toString();
    }
}

Related

  1. sha1sum(File file)
  2. SHA1Sum(final @Nonnull byte[] bytes)
  3. sha1sum(final String data)
  4. sha1sum(InputStream file)
  5. sha1ToHex(String input, String encoding)