p12.decrypt(pword.toCharArray());
KeyBag keyBag = p12.getKeyBag();
if (null == keyBag) {
throw new PKCSException("No private key found");
}
byte[] keyBagLocalKeyId = keyBag.getLocalKeyID();
this.key = keyBag.getPrivateKey();
CertificateBag[] certBags = p12.getCertificateBags();
if ((null == certBags) || (certBags.length == 0)) {
throw new PKCSException("No certificates found");
}
this.alias = new String(keyBagLocalKeyId);
X509Certificate myCert = null;
for( int i=0; i < certBags.length; i++) {
byte[] certBagLocalKeyId = certBags[i].getLocalKeyID();
if ((null != keyBagLocalKeyId) && (null != certBagLocalKeyId)) {
if (Arrays.equals(certBagLocalKeyId, keyBagLocalKeyId)) {
myCert = certBags[i].getCertificate();
break;
}
}
}
if (null == myCert) {
throw new PKCSException("No owner certificate found");
}
iaik.x509.X509Certificate[] certChain = CertificateBag.getCertificates(certBags);
this.certChain = Util.arrangeCertificateChain(certChain, false);
}