public static PrivateKey getPrivateKey(String pem) throws IOException, GeneralSecurityException {
	
		PrivateKey key = null;

            byte[] bytes = getFragmentOfPEM(pem, RSA_PRIVATE_KEY_PEM_HEADER,
                    RSA_PRIVATE_KEY_PEM_FOOTER);

            String rsa = new String(bytes);
            String split[] = rsa.split("-----");
            rsa = split[2];

            ASN1Sequence primitive = (ASN1Sequence) ASN1Sequence
                    .fromByteArray(Base64.decode(rsa.getBytes()));

            Enumeration<?> e = primitive.getObjects();
            BigInteger v = ((DERInteger) e.nextElement()).getValue();

            int version = v.intValue();
            if (version != 0 && version != 1) {
                throw new IllegalArgumentException(
                        "wrong version for RSA private key");
            }
            /**
             * In fact only modulus and private exponent are in use.
             */
            BigInteger modulus = ((DERInteger) e.nextElement()).getValue();
            BigInteger publicExponent = ((DERInteger) e.nextElement())
                    .getValue();
            BigInteger privateExponent = ((DERInteger) e.nextElement())
                    .getValue();
            BigInteger prime1 = ((DERInteger) e.nextElement()).getValue();
            BigInteger prime2 = ((DERInteger) e.nextElement()).getValue();
            BigInteger exponent1 = ((DERInteger) e.nextElement()).getValue();
            BigInteger exponent2 = ((DERInteger) e.nextElement()).getValue();
            BigInteger coefficient = ((DERInteger) e.nextElement()).getValue();

            RSAPrivateKeySpec rsaPrivKeySpec = new RSAPrivateKeySpec(modulus,
                    privateExponent);
            try{
            	KeyFactory kf = KeyFactory.getInstance("RSA");
            	key = kf.generatePrivate(rsaPrivKeySpec);
            }catch(GeneralSecurityException e1){
            	throw e1;
            }

        return key;
    }