Java SHA1 sha1(byte[] data)

Here you can find the source of sha1(byte[] data)

Description

sha

License

Open Source License

Declaration

public static byte[] sha1(byte[] data) throws NoSuchAlgorithmException,
            UnsupportedEncodingException 

Method Source Code

//package com.java2s;
/*-/*from  w  w w.  j a  v a  2 s  . c  o m*/
 * Copyright (C) 2011  Mobile Multimedia Laboratory, AUEB
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * Alternatively, this software may be distributed under the terms of the
 * BSD license.
 *
 * See LICENSE and COPYING for more details.
 */

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static byte[] sha1(byte[] data) throws NoSuchAlgorithmException,
            UnsupportedEncodingException {

        MessageDigest md = MessageDigest.getInstance("SHA-1");
        byte[] sha1Hash = new byte[20];
        byte[] id = new byte[8]; /* CHANGED array length, original data.length */

        sha1Hash = md.digest(data);

        // Id generation
        System.arraycopy(sha1Hash, 0, id, 0, 8);
        for (int i = 20; i < id.length; i++) {
            id[i] = 0;
        }

        return id;
    }

    public static byte[] sha1(String name) throws NoSuchAlgorithmException,
            UnsupportedEncodingException {

        byte[] buffer = name.getBytes("iso-8859-1");
        return sha1(buffer);
    }
}

Related

  1. sha1(byte[] bytes)
  2. SHA1(byte[] convertme)
  3. SHA1(byte[] data)
  4. sha1(byte[] data)
  5. sha1(byte[] data)
  6. sha1(byte[] data)
  7. SHA1(byte[] input)
  8. sha1(byte[] input)
  9. sha1(byte[] input)