I'm trying to implement my own version of authorization for HTTP requests. Now I'm facing a problem that I don't know how to resolve.
As shown in code below, I'm encrypting String message using RSA algorithm. But the problem is that as a result I'm getting object of class SealedObject. I need to have the possibility to use this encrypted string as header - for now using REST client like Postman. So, my question is: How can I parse SealedObject to String? Or what should I do to encrypt the message to String? Is this even possible?
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
KeyPair keyPair = kpg.generateKeyPair();
String message = "Secret message";
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, keyPair.getPublic());
SealedObject encryptedMessage = new SealedObject(message, cipher);
Thank you in advance :)