Java XML Hex sha1Hex(String data)

Here you can find the source of sha1Hex(String data)

Description

sha Hex

License

Apache License

Declaration

static String sha1Hex(String data) 

Method Source Code


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

import javax.xml.bind.DatatypeConverter;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    static String sha1Hex(String data) {
        MessageDigest digest = null;
        try {//ww  w  .  ja v a 2 s.c  o m
            digest = MessageDigest.getInstance("SHA-1");
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        try {
            digest.update(data.getBytes("utf8"));
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
        byte[] digestBytes = digest.digest();
        return DatatypeConverter.printHexBinary(digestBytes);
    }
}

Related

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