Peter Peter - 3 months ago 24
JSON Question

How to convert a PublicKey to JSON in Java?

I want to send a client's public key ( in JSON format to my server. I'm using Google's Gson library to convert in between, however, I'm getting a runtime exception which tells me that Key is an interface and I need some kind of adapter to parse it. Have anyone encountered this problem? Any solution is welcome, I just need to transfer the key via HTTP.

Thank you!

Answer Source

You can get the encoded key using the getEncoded() method and send that via JSON to your server.