Java SHA1 computeSHA1(ByteBuffer convertme, int offset, int len)

Here you can find the source of computeSHA1(ByteBuffer convertme, int offset, int len)

Description

compute SHA

License

GNU General Public License

Declaration

public static byte[] computeSHA1(ByteBuffer convertme, int offset, int len) 

Method Source Code

//package com.java2s;
/*//  w w w  . j  a v  a2  s.  c o  m
 * This is the source code of Telegram for Android v. 2.x.x.
 * It is licensed under GNU GPL v. 2 or later.
 * You should have received a copy of the license in this archive (see LICENSE).
 *
 * Copyright Nikolai Kudashov, 2013-2015.
 */

import java.nio.ByteBuffer;
import java.security.*;

public class Main {
    public static byte[] computeSHA1(byte[] convertme, int offset, int len) {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            md.update(convertme, offset, len);
            return md.digest();
        } catch (Exception e) {
            //FileLog.e("tmessages", e);
        }
        return null;
    }

    public static byte[] computeSHA1(ByteBuffer convertme, int offset, int len) {
        int oldp = convertme.position();
        int oldl = convertme.limit();
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            convertme.position(offset);
            convertme.limit(len);
            md.update(convertme);
            return md.digest();
        } catch (Exception e) {
            //FileLog.e("tmessages", e);
        } finally {
            convertme.limit(oldl);
            convertme.position(oldp);
        }
        return new byte[0];
    }

    public static byte[] computeSHA1(ByteBuffer convertme) {
        return computeSHA1(convertme, 0, convertme.limit());
    }

    public static byte[] computeSHA1(byte[] convertme) {
        return computeSHA1(convertme, 0, convertme.length);
    }
}

Related

  1. computeSHA1(byte[] ba)
  2. computeSha1(byte[] data)
  3. computeSha1(ReadableByteChannel channel)
  4. computeSha1AsHexString(String strToHash)
  5. computeSHA1Hash(byte[] data)
  6. digestSHA1(byte[] data)