Skip to content

Instantly share code, notes, and snippets.

@pavlo
Last active February 2, 2017 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavlo/7049c6607cb7a410fe02d8ed15c9fbf9 to your computer and use it in GitHub Desktop.
Save pavlo/7049c6607cb7a410fe02d8ed15c9fbf9 to your computer and use it in GitHub Desktop.
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