private static byte[] getPKCS1BytesFromPKCS8Bytes(byte[] bytes) {
        /*
         * DER format: http://en.wikipedia.org/wiki/Distinguished_Encoding_Rules
         * PKCS#8: http://tools.ietf.org/html/rfc5208
         */
        int bIndex = 0;

        // Start with PrivateKeyInfo::=SEQUENCE
        // 0x30 Sequence
        if (bytes[bIndex] != 48) {
        	LOG.error("Not a PKCS#8 private key");
            throw new IllegalArgumentException("Not a PKCS#8 private key");
        }

        // next byte contain the number of bytes
        // of SEQUENCE element (length field)
        ++bIndex;

        // Get number of bytes of element
        int sizeOfContent = getSizeOfContent(bytes, bIndex);
        int sizeOfLengthField = getSizeOfLengthField(bytes, bIndex);

        LOG.debug("PrivateKeyInfo(SEQUENCE): Number of bytes:"
                + sizeOfContent
                + "PrivateKeyInfo(SEQUENCE): Number of bytes of length field:"
                + sizeOfLengthField);

        // version::=INTEGER
        // shift index to version element
        bIndex += sizeOfLengthField;

        // 0x02 Integer
        if (bytes[bIndex] != 2) {
        	LOG.error("Not a PKCS#8 private key");
            throw new IllegalArgumentException("Not a PKCS#8 private key");
        }
        ++bIndex;

        // Get number of bytes of element
        sizeOfContent = getSizeOfContent(bytes, bIndex);
        sizeOfLengthField = getSizeOfLengthField(bytes, bIndex);

        LOG.debug("Version(INTEGER): Number of bytes:" + sizeOfContent
                + "Version(INTEGER): Number of bytes of length field:"
                + sizeOfLengthField);

        // PrivateKeyAlgorithm::= PrivateKeyAlgorithmIdentifier
        // shift index to PrivateKeyAlgorithm element
        bIndex = bIndex + sizeOfLengthField + sizeOfContent;

        // ? PrivateKeyAlgorithmIdentifier
        // if (bytes[bIndex] != ?) {
        // throw new IllegalArgumentException("Not a PKCS#8 private key");
        // }

        ++bIndex;

        // Get number of bytes of element
        sizeOfContent = getSizeOfContent(bytes, bIndex);
        sizeOfLengthField = getSizeOfLengthField(bytes, bIndex);
        LOG.debug("PrivateKeyAlgorithm(PrivateKeyAlgorithmIdentifier): Number of bytes:"
                + sizeOfContent
                + "PrivateKeyAlgorithm(PrivateKeyAlgorithmIdentifier): "
                + "Number of bytes of length field:" + sizeOfLengthField);

        // PrivateKey::= OCTET STRING
        // shift index to PrivateKey element
        bIndex = bIndex + sizeOfLengthField + sizeOfContent;

        // 0x04 OCTET STRING
        if (bytes[bIndex] != 4) {
            throw new IllegalArgumentException("Not a PKCS#8 private key");
        }
        ++bIndex;

        // Get number of bytes of element
        sizeOfContent = getSizeOfContent(bytes, bIndex);
        sizeOfLengthField = getSizeOfLengthField(bytes, bIndex);

        LOG.debug("PrivateKey(OCTET STRING: Number of bytes:"
                + sizeOfContent
                + "PrivateKey(OCTET STRING): Number of bytes of length field:"
                + sizeOfLengthField);

        return Arrays.copyOfRange(bytes, bIndex + sizeOfLengthField, bIndex
                + sizeOfLengthField + sizeOfContent);
    }