org.spongycastle.pkcs.PKCS12SafeBagFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pkix Show documentation
Show all versions of pkix Show documentation
Spongy Castle is a package-rename (org.bouncycastle.* to org.spongycastle.*) of Bouncy Castle
intended for the Android platform. Android unfortunately ships with a stripped-down version of
Bouncy Castle, which prevents easy upgrades - Spongy Castle overcomes this and provides a full,
up-to-date version of the Bouncy Castle cryptographic libs.
The newest version!
package org.spongycastle.pkcs;
import org.spongycastle.asn1.ASN1OctetString;
import org.spongycastle.asn1.ASN1Sequence;
import org.spongycastle.asn1.pkcs.ContentInfo;
import org.spongycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.spongycastle.asn1.pkcs.SafeBag;
import org.spongycastle.cms.CMSEncryptedData;
import org.spongycastle.cms.CMSException;
import org.spongycastle.operator.InputDecryptorProvider;
public class PKCS12SafeBagFactory
{
private ASN1Sequence safeBagSeq;
public PKCS12SafeBagFactory(ContentInfo info)
{
if (info.getContentType().equals(PKCSObjectIdentifiers.encryptedData))
{
throw new IllegalArgumentException("encryptedData requires constructor with decryptor.");
}
this.safeBagSeq = ASN1Sequence.getInstance(ASN1OctetString.getInstance(info.getContent()).getOctets());
}
public PKCS12SafeBagFactory(ContentInfo info, InputDecryptorProvider inputDecryptorProvider)
throws PKCSException
{
if (info.getContentType().equals(PKCSObjectIdentifiers.encryptedData))
{
CMSEncryptedData encData = new CMSEncryptedData(org.spongycastle.asn1.cms.ContentInfo.getInstance(info));
try
{
this.safeBagSeq = ASN1Sequence.getInstance(encData.getContent(inputDecryptorProvider));
}
catch (CMSException e)
{
throw new PKCSException("unable to extract data: " + e.getMessage(), e);
}
return;
}
throw new IllegalArgumentException("encryptedData requires constructor with decryptor.");
}
public PKCS12SafeBag[] getSafeBags()
{
PKCS12SafeBag[] safeBags = new PKCS12SafeBag[safeBagSeq.size()];
for (int i = 0; i != safeBagSeq.size(); i++)
{
safeBags[i] = new PKCS12SafeBag(SafeBag.getInstance(safeBagSeq.getObjectAt(i)));
}
return safeBags;
}
}