在我的 Android 项目中,我已将我的证书文件raw/
作为raw/mycert.p12
.
然后,我尝试X509Certificate
通过执行以下操作来获取实例:
//Get input stream of mycert.p12, the input stream is not null
InputStream inputStream = mContext.getResources().openRawResource(com.my.app.R.raw.mycert);
//Get an instance of CertificateFactory
CertificateFactory cf = CertificateFactory.getInstance("X.509");
//Get buffered input stream
InputStream bis = new BufferedInputStream(inputStream);
//Generate certificate instance
//NullpointerException here...
X509Certificate cert = (X509Certificate) cf.generateCertificates(bis);
我也尝试过手动安装此证书(mycert.p12),我确定它是 x.509 类型的证书。
但是为什么从输入流生成它的实例时会得到NullpointerException呢?