static BigInteger getRSAPublicExponentFromPkcs8Encoded(byte[] encoded) throws InvalidKeySpecException {
		if (encoded == null) {
			throw new InvalidKeySpecException("encoded key is null");
		}

		try {
			SimpleDERReader reader = new SimpleDERReader(encoded);
			reader.resetInput(reader.readSequenceAsByteArray());
			if (!reader.readInt().equals(BigInteger.ZERO)) {
				throw new InvalidKeySpecException("PKCS#8 is not version 0");
			}

			reader.readSequenceAsByteArray();  // OID sequence
			reader.resetInput(reader.readOctetString());  // RSA key bytes
			reader.resetInput(reader.readSequenceAsByteArray());  // RSA key sequence

			if (!reader.readInt().equals(BigInteger.ZERO)) {
				throw new InvalidKeySpecException("RSA key is not version 0");
			}

			reader.readInt();  // modulus
			return reader.readInt();  // public exponent
		} catch (IOException e) {
			Log.w(TAG, "Could not read public exponent", e);
			throw new InvalidKeySpecException("Could not read key", e);
		}
	}
@Test
	public void getRSAPublicExponentFromPkcs8Encoded_Success() throws Exception {
		assertEquals(RSA_KEY_E, PubkeyUtils.getRSAPublicExponentFromPkcs8Encoded(RSA_KEY_PKCS8));
	}