Base64PublicKeyDecoder implements KeyDecoder { @Override public PublicKey decode(String input) throws DecodingException { byte[] decoded = decoder.decode(input); X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(decoded); try { return fact.generatePublic(x509KeySpec); } catch (InvalidKeySpecException e) { throw new DecodingException(e); } } Base64PublicKeyDecoder(); @Override PublicKey decode(String input);  }
@Test public void test() throws Exception { PublicKey decoded = decoder.decode(encoded); assertEquals(decoded, key); }
@Test public void testException() throws Exception { try { decoder.decode("not a key"); fail("Should have thrown an exception here"); } catch (DecodingException e) { } }