4

I am trying to convert PublicKey to String but I don't know how to do it properly. Following code doesn't give me correct key, so how convert it?

byte[] publicKeyBytes = userKeys.getPublic().getEncoded(); String pKstring = new String(publicKeyBytes); 

1 Answer 1

7

I find out solution, below code is correct:

byte[] publicKeyBytes = Base64.encode(userKeys.getPublic().getEncoded(),0); String pubKey = new String(publicKeyBytes); 
Sign up to request clarification or add additional context in comments.

1 Comment

You should use Base64.DEFAULT instead of 0, even the result is same.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.