Java XML Hex sha1Hex(final String text)

Here you can find the source of sha1Hex(final String text)

Description

sha Hex

License

Apache License

Declaration

public static String sha1Hex(final String text) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import javax.xml.bind.DatatypeConverter;
import java.security.MessageDigest;

public class Main {
    public static String sha1Hex(final String text) {

        try {//from  w ww .jav  a 2s.c  o m
            final byte[] bytesOfMessage = text.getBytes("UTF-8");
            final MessageDigest md = MessageDigest.getInstance("SHA1");
            final byte[] digest = md.digest(bytesOfMessage);

            return DatatypeConverter.printHexBinary(digest).toLowerCase();
        } catch (Exception e) {
            throw new RuntimeException();
        }
    }
}

Related

  1. hexToBytes(final String s)
  2. hexToString(String str)
  3. printHexBinary(byte[] in)
  4. printHexBinary(final byte[] deviceMessage)
  5. readHexString(ByteBuffer buf)
  6. sha1Hex(String data)
  7. sha1Hex(String message)
  8. stringToHex(String str)
  9. toByteArray(String hex)