### Question:
PubkeyUtils { public static KeyPair recoverKeyPair(byte[] encoded) throws NoSuchAlgorithmException, InvalidKeySpecException { final String algo = getAlgorithmForOid(getOidFromPkcs8Encoded(encoded)); final KeySpec privKeySpec = new PKCS8EncodedKeySpec(encoded); final KeyFactory kf = KeyFactory.getInstance(algo); final PrivateKey priv = kf.generatePrivate(privKeySpec); return new KeyPair(recoverPublicKey(kf, priv), priv); } 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 recoverKeyPair_Dsa() throws Exception { KeyPair kp = PubkeyUtils.recoverKeyPair(DSA_KEY_PKCS8); DSAPublicKey pubKey = (DSAPublicKey) kp.getPublic(); assertEquals(DSA_KEY_pub, pubKey.getY()); DSAParams params = pubKey.getParams(); assertEquals(params.getG(), DSA_KEY_G); assertEquals(params.getP(), DSA_KEY_P); assertEquals(params.getQ(), DSA_KEY_Q); }
@Test public void recoverKeyPair_Rsa() throws Exception { KeyPair kp = PubkeyUtils.recoverKeyPair(RSA_KEY_PKCS8); RSAPublicKey pubKey = (RSAPublicKey) kp.getPublic(); assertEquals(RSA_KEY_N, pubKey.getModulus()); assertEquals(RSA_KEY_E, pubKey.getPublicExponent()); }
@Test public void recoverKeyPair_Ec() throws Exception { KeyPair kp = PubkeyUtils.recoverKeyPair(EC_KEY_PKCS8); ECPublicKey pubKey = (ECPublicKey) kp.getPublic(); assertEquals(EC_KEY_pub_x, pubKey.getW().getAffineX()); assertEquals(EC_KEY_pub_y, pubKey.getW().getAffineY()); }