Last active
February 2, 2017 14:14
-
-
Save pavlo/7049c6607cb7a410fe02d8ed15c9fbf9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Optional<ECPublicKey> parseEcPublicKey(String json) { | |
try { | |
return Optional.ofNullable(((ECKey) JWK.parse(json)).toECPublicKey()); | |
} catch (ParseException | JOSEException e) { | |
// todo: log exception here | |
return Optional.empty(); | |
} | |
} | |
private String ecPublicKeyToJwk(ECPublicKey key) { | |
return new ECKey.Builder(ECKey.Curve.P_256, key).build().toJSONString(); | |
} | |
public static Optional<RSAPublicKey> parseRsaPublicKey(String json) { | |
try { | |
return Optional.ofNullable(((RSAKey) JWK.parse(json)).toRSAPublicKey()); | |
} catch (ParseException | JOSEException e) { | |
// todo: log exception here | |
return Optional.empty(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment