### Question:
PubkeyUtils { static String getOidFromPkcs8Encoded(byte[] encoded) throws NoSuchAlgorithmException { if (encoded == null) { throw new NoSuchAlgorithmException("encoding is null"); } try { SimpleDERReader reader = new SimpleDERReader(encoded); reader.resetInput(reader.readSequenceAsByteArray()); reader.readInt(); reader.resetInput(reader.readSequenceAsByteArray()); return reader.readOid(); } catch (IOException e) { Log.w(TAG, "Could not read OID", e); throw new NoSuchAlgorithmException("Could not read key", e); } } private  PubkeyUtils(); static String formatKey(Key key); static byte[] getEncodedPrivate(PrivateKey pk, String secret); static PrivateKey decodePrivate(byte[] encoded, String keyType); static PrivateKey decodePrivate(byte[] encoded, String keyType, String secret); static int getBitStrength(byte[] encoded, String keyType); static PublicKey decodePublic(byte[] encoded, String keyType); static KeyPair convertToKeyPair(PubkeyBean keybean, String password); static KeyPair recoverKeyPair(byte[] encoded); static String convertToOpenSSHFormat(PublicKey pk, String origNickname); static byte[] extractOpenSSHPublic(KeyPair pair); static String exportPEM(PrivateKey key, String secret); static final String PKCS8_START; static final String PKCS8_END; }### Answer:
@Test public void getOidFromPkcs8Encoded_Ec_NistP256() throws Exception { assertEquals("1.2.840.10045.2.1", PubkeyUtils.getOidFromPkcs8Encoded(EC_KEY_PKCS8)); }
@Test public void getOidFromPkcs8Encoded_Rsa() throws Exception { assertEquals("1.2.840.113549.1.1.1", PubkeyUtils.getOidFromPkcs8Encoded(RSA_KEY_PKCS8)); }
@Test public void getOidFromPkcs8Encoded_Dsa() throws Exception { assertEquals("1.2.840.10040.4.1", PubkeyUtils.getOidFromPkcs8Encoded(DSA_KEY_PKCS8)); }
@Test public void getOidFromPkcs8Encoded_Null_Failure() throws Exception { try { PubkeyUtils.getOidFromPkcs8Encoded(null); fail("Should throw NoSuchAlgorithmException"); } catch (NoSuchAlgorithmException expected) { } }
@Test public void getOidFromPkcs8Encoded_NotCorrectDer_Failure() throws Exception { try { PubkeyUtils.getOidFromPkcs8Encoded(new byte[] { 0x30, 0x01, 0x00 }); fail("Should throw NoSuchAlgorithmException"); } catch (NoSuchAlgorithmException expected) { } }