Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7611273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:37:53+00:00 2026-05-31T01:37:53+00:00

Hi i am using the following code to parse a certificate details.Everything is fine

  • 0

Hi i am using the following code to parse a certificate details.Everything is fine except a bit problem mentioned below.

package android.net.http;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileReader;
import java.io.InputStream;
import java.security.cert.Certif`enter code here`icate;
import java.security.cert.CertificateFactory;
import java.security.cert.CertificateParsingException;
import java.security.cert.X509Certificate;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.util.Base64;
import android.util.Base64InputStream;
import android.util.Log;

 public class SslCertificate1Activity extends Activity
 {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

try  {
String text = "-----BEGIN CERTIFICATE-----\n"+
    "MIIC/TCCAmagAwIBAgIBKjANBgkqhkiG9w0BA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+Q3hHuU6in3AqLfWH1w==\n"+
    "-----END CERTIFICATE-----";
int startIndex = 0;
String cert = text.substring(startIndex,text.length()); 
    byte[] certBytes = cert.getBytes();
    InputStream in = new Base64InputStream(new ByteArrayInputStream(
            certBytes), 0);
CertificateFactory certFact = CertificateFactory.getInstance ("X.509");
    Certificate certGen = certFact.generateCertificate(in); 
    X509Certificate x509 = (X509Certificate) certGen; 
     Log.i("","certificate details:"+x509);
    } 
    catch (Exception e)  
    {
        Log.e("testapp", "exception: " + e.getMessage()); 
    }  
}
 }

and I am getting android.util.BASE64DataException:bad base-64 at the foloowing line when I launced debugger:-

Certificate certGen = certFact.generateCertificate(in);

Seems like there is something wrong with Base64InputStream.Please help in rectifying the Exception.
Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:37:54+00:00Added an answer on May 31, 2026 at 1:37 am

    No, nothing is wrong with Base64InputStream. When in doubt, you should suspect your own code of being incorrect rather than everyone else’s.

    What’s wrong is that you’re giving Base64InputStream data that ends with “—–END CERTIFICATE—–” after the padding part.

    You should only be passing in the bit between “—–BEGIN CERTIFICATE—–” and “—–END CERTIFICATE—–“.

    It looks like you’ve started thinking about that already here:

    int startIndex = 0;
    String cert = text.substring(startIndex,text.length()); 
    

    … but that code isn’t going to do anything – when startIndex is 0, substring is going to return the whole string…

    Personally I’d consider doing the Base64 conversion first using the Base64 class to convert the base64 part of the string (you still need to get the substring) to a byte[] and then create a ByteArrayInputStream around that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am using the below json method and following code to parse json method
I'm using the following code to parse an RSS Feed. Which works fine for
I'm using following code to parse rather large xml file (> 50GB): use XML::Parser;
Currently I am using the following code to parse the JSON link sent. This
I am using the following code to generate and parse the XML. The method
I'm using the following code with the javax.swing.text.html.parser.ParserDelegator in order to parse hyperlinks from
In c#,I am using the following code: IPAddress localaddress=IPAddress.Parse(127.0.0.1); to get a System.Net.IPAddress instance
for my application i have to parse CSV file using Erlang.following is the code
I am using following code to parse JSON- NSString *responseString = [[NSString alloc] initWithData:responseData
I'm currently using the following code to parse a part of an Xml file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.