private static int getSizeOfContent(byte[] bytes, int bIndex) {
        byte aux = bytes[bIndex];

        if ((aux & 0x80) == 0) { // applies mask
            // short form
            return aux;
        }

        /*
         * long form: if first bit begins with 1 then the rest of bits are the
         * number of bytes that contain the number of bytes of element 375 is
         * 101110111 then in 2 bytes: 00000001 01110111 that is the number of
         * bytes that contain the number of bytes ex: 375 is 101110111 then in 2
         * bytes: 00000001 01110111 .
         */
        byte numOfBytes = (byte) (aux & 0x7F);

        if (numOfBytes * 8 > 32) {
            throw new IllegalArgumentException("ASN.1 field too long");
        }

        int contentLength = 0;

        // find out the number of bits in the bytes
        for (int i = 0; i < numOfBytes; ++i) {
            contentLength = (contentLength << 8) + bytes[(bIndex + 1 + i)];
        }

        return contentLength;
    }