CertificateException bei generateCertificate ()
Ich entwickle meine Android App. Ich versuche das zu generierenX509-Zertifikat Instanz aus meiner Zertifikatdatei streamen, aber bekommenCertificateException
Hier ist mein einfacher Code:
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
...
public class CertMgr {
//my certification file 'mycert.p12' located in my app internal storage
File certFile = GET_CERT();
X509Certificate cert = null;
try {
FileInputStream fis = new FileInputStream(certFile);
BufferedInputStream bis = new BufferedInputStream(fis);
CertificateFactory cf = CertificateFactory.getInstance("X.509");
if(bis.available() > 0){
//I got CertificateException here, see the stack trace
cert = (X509Certificate) cf.generateCertificate(bis); //line nr 150
}
}catch(...)
{...}
...
}
Stack-Trace:
javax.security.cert.CertificateException: org.apache.harmony.security.asn1.ASN1Exception: ASN.1 Sequence: mandatory value is missing at [4]
11-11 17:30:20.731: W/System.err(11529): at javax.security.cert.X509Certificate.getInstance(X509Certificate.java:94)
11-11 17:30:20.731: W/System.err(11529): at javax.security.cert.X509Certificate.getInstance(X509Certificate.java:213)
11-11 17:30:20.731: W/System.err(11529): at com.my.app.CertMgr.getCert(CertMgr.java:150)
Könnte mir bitte jemand erklären, warum ich diese Ausnahme erhalte?
P .: Hier sind die Klassen, die ich von Android SDK verwendeX509-Zertifikat , CertificateFactory
Wenn Sie neugierig sind, warum ich das mache, ist der Grund, dass ich möchte, dass meine App das Zertifikat installieren kann (mycert.p12) durch den folgenden Code (wenn der obige Code ordnungsgemäß funktioniert):
Intent installIntent = KeyChain.createInstallIntent();
installIntent.putExtra(KeyChain.EXTRA_CERTIFICATE, cert.getEncoded());
installIntent.putExtra(KeyChain.EXTRA_NAME, MY_CERT);
startActivityForResult(installIntent, INSTALL_KEYCHAIN_CODE);