Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Illegal character in Base64 encoded data

843811May 22 2007 — edited May 23 2007
Hi,

I'm trying to get a print out the public key as a String, which I am getting it in as a base64 encoded, but I get error:

Exception in thread "main" java.lang.IllegalArgumentException: Illegal character in Base64 encoded data.

Code below:
public static void main(String[] args) {
		File pubKeyFile = new File("C:\\usercert.pem");
		StringBuffer buffer = new StringBuffer();
		
			try {
				FileInputStream fis = new FileInputStream(pubKeyFile);
				try {
					InputStreamReader isr = new InputStreamReader(fis, "UTF8");
					Reader in = new BufferedReader(isr);
					int ch;
					while((ch = in.read()) > -1) {
						buffer.append((char)ch);
					}
					in.close();
					String key = buffer.toString();
					System.out.println("key is: " + key);

                                       //This is where the code fails:
					String keyDecode = Base64.decodeString(key);
					System.out.println("key ecode is: " + keyDecode);
				} catch (UnsupportedEncodingException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 20 2007
Added on May 22 2007
6 comments
6,297 views