public static Sha1Hash forByteBuffer (ByteBuffer buffer) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA1");
        } catch (NoSuchAlgorithmException e) {
            // If the SHA1 algorithm doesn't exist, returns null
            return null;
        }

        ByteBuffer buf = buffer.duplicate();

        byte[] arr = new byte[64 * 1024];
        while (buf.remaining() > 0) {
            int length = Math.min(arr.length, buf.remaining());
            buf.get(arr, 0, length);
            md.update(arr, 0, length);
        }

        return new Sha1Hash(md.digest());
    }