Java SHA1 doSHA1(byte[] buf)

Here you can find the source of doSHA1(byte[] buf)

Description

do SHA

License

Apache License

Declaration

static String doSHA1(byte[] buf) 

Method Source Code

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

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

import java.util.Formatter;

public class Main {
    static String doSHA1(byte[] buf) {
        return doSHA1(buf, 0, buf.length);
    }/*  w w  w  .j  a v  a2 s  .co m*/

    static String doSHA1(byte[] buf, int off, int len) {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA1");
            md.update(buf, off, len);
            byte[] hv = md.digest();
            Formatter f = new Formatter();
            for (byte b : hv) {
                f.format("%02x", b & 0xFF);
            }
            return f.toString();
        } catch (NoSuchAlgorithmException nsae) {
            throw new Error(nsae);
        }
    }
}

Related

  1. digestSHA1(byte[] data)
  2. digestSHA1(String data)
  3. digestSHA1(String login, String pass)
  4. digestSHA1(String text)
  5. digestSha1Hex(String source)
  6. doSHA1(byte[] buf, int off, int len)
  7. generateSHA1(String message)
  8. generateSHA1ChecksumFile(String filename)
  9. generateSHA1Key(String input)