I am doing a server-client communication with encryption and I don`t know how to send a public key over the network.

Is there a way to cast the Key type to some other type (easy to send by network like bytes, chars) and then recreate that Key using those primitive types?(I would prefer this if its possible)

Or should I use ObjectOutputStream and try to send the key using that?

Or should I don`t bother with that and just use SSLSocket?