List of usage examples for org.bouncycastle.asn1.pkcs ContentInfo getContentType
public ASN1ObjectIdentifier getContentType()
From source file:de.carne.certmgr.store.provider.bouncycastle.PKCS12Decoder.java
License:Open Source License
public Collection<Object> decode() throws IOException, PasswordRequiredException { for (ContentInfo contentInfo : this.pkcs12.getContentInfos()) { if (contentInfo.getContentType().equals(PKCSObjectIdentifiers.encryptedData)) { PKCS12SafeBagFactory bagFactory = null; PKCSException decryptException = null; while (bagFactory == null) { try { bagFactory = new PKCS12SafeBagFactory(contentInfo, getInputDecryptorProvider(decryptException)); } catch (PKCSException e) { decryptException = e; }/*from w w w . jav a 2 s . c om*/ } decodeBags(bagFactory.getSafeBags()); } else { PKCS12SafeBagFactory bagFactory = new PKCS12SafeBagFactory(contentInfo); decodeBags(bagFactory.getSafeBags()); } } return this.decoded; }
From source file:fi.laverca.Pkcs7.java
License:Apache License
/** * Convert a byte array to a PKCS7 SignedData object * @param bytes byte array//from w w w.j a v a 2s . c o m * @return PKCS7 SignedData object */ public static SignedData bytesToPkcs7SignedData(byte[] bytes) { if (bytes == null) { throw new IllegalArgumentException("null bytes"); } ASN1InputStream ais = new ASN1InputStream(bytes); ASN1Object asn1 = null; try { asn1 = ais.readObject(); } catch (IOException ioe) { throw new IllegalArgumentException("not a pkcs7 signature"); } finally { try { ais.close(); } catch (IOException e) { // Ignore } } ContentInfo ci = ContentInfo.getInstance(asn1); DERObjectIdentifier typeId = ci.getContentType(); if (!typeId.equals(PKCSObjectIdentifiers.signedData)) { throw new IllegalArgumentException("not a pkcs7 signature"); } return SignedData.getInstance(ci.getContent()); }