Hi I am trying to remove the header and footer off a public key that is being stored as a string. I have managed to work out how to remove the "begin" header by removing everything up to the first "\n",
-----BEGIN PUBLIC KEY-----\n
with this code.
String s1 = pKey.substring(pKey.indexOf("\n")+1);
I am however struggling to remove the footer from the end up to the last "\n".
\n-----END PUBLIC KEY-----
There must be a cleaner way to remove them both.
Public key can be Some thing like this "-----BEGIN PUBLIC KEY----\nkey\n-----END PUBLIC KEY-----"
So to remove header and footer from string you can use
pKey.substring(pKey.indexOf("\n")+1, pKey.lastIndexOf("\n"));
or other way just replace header and footer directly by empty , since it won't be present in key
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With