Java SHA1 SHA1Encode(String sourceString)

Here you can find the source of SHA1Encode(String sourceString)

Description

SHA Encode

License

Open Source License

Declaration

public static String SHA1Encode(String sourceString) 

Method Source Code


//package com.java2s;
import java.security.MessageDigest;

public class Main {
    public static String SHA1Encode(String sourceString) {
        String resultString = null;
        try {/*from  w ww  . jav  a2  s .  co  m*/
            resultString = new String(sourceString);
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            resultString = byte2hexString(md.digest(resultString.getBytes()));
        } catch (Exception ex) {
        }
        return resultString;
    }

    public static final String byte2hexString(byte[] bytes) {
        StringBuffer buf = new StringBuffer(bytes.length * 2);
        for (int i = 0; i < bytes.length; i++) {
            if (((int) bytes[i] & 0xff) < 0x10) {
                buf.append("0");
            }
            buf.append(Long.toString((int) bytes[i] & 0xff, 16));
        }
        return buf.toString().toUpperCase();
    }
}

Related

  1. sha1Digest(byte[] bytes)
  2. sha1Digest(final InputStream data)
  3. sha1Digest(String src)
  4. sha1DigestAsHex(String data)
  5. sha1Encode(byte[] content)
  6. sha1Hash()
  7. sha1hash(byte[] blob)
  8. sha1Hash(byte[] data)
  9. sha1hash(Collection nquads)