本文整理汇总了Java中org.bouncycastle.asn1.pkcs.ContentInfo类的典型用法代码示例。如果您正苦于以下问题:Java ContentInfo类的具体用法?Java ContentInfo怎么用?Java ContentInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ContentInfo类属于org.bouncycastle.asn1.pkcs包,在下文中一共展示了ContentInfo类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PKCS12SafeBagFactory
import org.bouncycastle.asn1.pkcs.ContentInfo; //导入依赖的package包/类
public PKCS12SafeBagFactory(ContentInfo info, InputDecryptorProvider inputDecryptorProvider)
throws PKCSException
{
if (info.getContentType().equals(PKCSObjectIdentifiers.encryptedData))
{
CMSEncryptedData encData = new CMSEncryptedData(org.bouncycastle.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.");
}
示例2: addData
import org.bouncycastle.asn1.pkcs.ContentInfo; //导入依赖的package包/类
/**
* Add a SafeBag that is to be included as is.
*
* @param data the SafeBag to add.
* @return this builder.
* @throws IOException
*/
public PKCS12PfxPduBuilder addData(PKCS12SafeBag data)
throws IOException
{
dataVector.add(new ContentInfo(PKCSObjectIdentifiers.data, new DEROctetString(new DLSequence(data.toASN1Structure()).getEncoded())));
return this;
}
示例3: build
import org.bouncycastle.asn1.pkcs.ContentInfo; //导入依赖的package包/类
/**
* Build the Pfx structure, protecting it with a MAC calculated against the passed in password.
*
* @param macCalcBuilder a builder for a PKCS12 mac calculator.
* @param password the password to use.
* @return a Pfx object.
* @throws PKCSException on a encoding or processing error.
*/
public PKCS12PfxPdu build(PKCS12MacCalculatorBuilder macCalcBuilder, char[] password)
throws PKCSException
{
AuthenticatedSafe auth = AuthenticatedSafe.getInstance(new DLSequence(dataVector));
byte[] encAuth;
try
{
encAuth = auth.getEncoded();
}
catch (IOException e)
{
throw new PKCSException("unable to encode AuthenticatedSafe: " + e.getMessage(), e);
}
ContentInfo mainInfo = new ContentInfo(PKCSObjectIdentifiers.data, new DEROctetString(encAuth));
MacData mData = null;
if (macCalcBuilder != null)
{
MacDataGenerator mdGen = new MacDataGenerator(macCalcBuilder);
mData = mdGen.build(password, encAuth);
}
//
// output the Pfx
//
Pfx pfx = new Pfx(mainInfo, mData);
return new PKCS12PfxPdu(pfx);
}
示例4: getContentInfos
import org.bouncycastle.asn1.pkcs.ContentInfo; //导入依赖的package包/类
/**
* Return the content infos in the AuthenticatedSafe contained in this Pfx.
*
* @return an array of ContentInfo.
*/
public ContentInfo[] getContentInfos()
{
ASN1Sequence seq = ASN1Sequence.getInstance(ASN1OctetString.getInstance(this.pfx.getAuthSafe().getContent()).getOctets());
ContentInfo[] content = new ContentInfo[seq.size()];
for (int i = 0; i != seq.size(); i++)
{
content[i] = ContentInfo.getInstance(seq.getObjectAt(i));
}
return content;
}
示例5: obtenirDadesCertificatNoPdf
import org.bouncycastle.asn1.pkcs.ContentInfo; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "resource" })
private List<DadesCertificat> obtenirDadesCertificatNoPdf(
byte[] signatura) throws Exception {
X509Certificate[] certificats = null;
byte[] pkcs7Bytes = signatura;
ASN1InputStream asn1is = new ASN1InputStream(new ByteArrayInputStream(pkcs7Bytes));
ContentInfo pkcs7Info = ContentInfo.getInstance(asn1is.readObject());
SignedData signedData = SignedData.getInstance(pkcs7Info.getContent());
ASN1Set signerInfos = signedData.getSignerInfos();
int numSignatures = signerInfos.size();
if (numSignatures > 0) {
afegirProveidorBouncyCastle();
CMSSignedData cmsSignedData = new CMSSignedData(pkcs7Bytes);
SignerInformationStore signers = cmsSignedData.getSignerInfos();
CertStore certStore = cmsSignedData.getCertificatesAndCRLs("Collection", "BC");
List<X509Certificate> certs = new ArrayList<X509Certificate>();
for (SignerInformation signer: (Collection<SignerInformation>)signers.getSigners()) {
for (Certificate cert: certStore.getCertificates(signer.getSID())) {
if (cert instanceof X509Certificate)
certs.add((X509Certificate)cert);
}
}
certificats = certs.toArray(new X509Certificate[certs.size()]);
if (certificats.length != 1)
throw new SignaturaPluginException("Aquesta signatura conté més d'un certificat");
//resposta.setInfoCertificat(getInfoCertificat(certificats[0]));
List<DadesCertificat> dadesCertificats = new ArrayList<DadesCertificat>();
dadesCertificats.add(getDadesCertificat(certificats[0]));
return dadesCertificats;
}
return null;
}
示例6: bytesToPkcs7SignedData
import org.bouncycastle.asn1.pkcs.ContentInfo; //导入依赖的package包/类
/**
* Convert a byte array to a PKCS7 SignedData object
* @param bytes byte array
* @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);
ASN1ObjectIdentifier typeId = ci.getContentType();
if( ! typeId.equals(PKCSObjectIdentifiers.signedData)) {
throw new IllegalArgumentException("not a pkcs7 signature");
}
return SignedData.getInstance(ci.getContent());
}
示例7: getSafeBagFactory
import org.bouncycastle.asn1.pkcs.ContentInfo; //导入依赖的package包/类
private static PKCS12SafeBagFactory getSafeBagFactory(ContentInfo contentInfo) {
return new PKCS12SafeBagFactory(contentInfo);
}
示例8: testKeyBag
import org.bouncycastle.asn1.pkcs.ContentInfo; //导入依赖的package包/类
public void testKeyBag()
throws Exception
{
OutputEncryptor encOut = new BcPKCS12PBEOutputEncryptorBuilder(PKCSObjectIdentifiers.pbeWithSHAAnd3_KeyTripleDES_CBC, new CBCBlockCipher(new DESedeEngine())).build(passwd);
InputDecryptorProvider inputDecryptorProvider = new BcPKCS12PBEInputDecryptorProviderBuilder().build(passwd);
KeyFactory fact = KeyFactory.getInstance("RSA", BC);
PrivateKey privKey = fact.generatePrivate(privKeySpec);
PKCS12SafeBagBuilder keyBagBuilder = new JcaPKCS12SafeBagBuilder(privKey);
keyBagBuilder.addBagAttribute(PKCSObjectIdentifiers.pkcs_9_at_friendlyName, new DERBMPString("Eric's Key"));
PKCS12PfxPduBuilder builder = new PKCS12PfxPduBuilder();
builder.addEncryptedData(encOut, keyBagBuilder.build());
PKCS12PfxPdu pfx = builder.build(new BcPKCS12MacCalculatorBuilder(), passwd);
assertTrue(pfx.hasMac());
assertTrue(pfx.isMacValid(new BcPKCS12MacCalculatorBuilderProvider(BcDefaultDigestProvider.INSTANCE), passwd));
ContentInfo[] infos = pfx.getContentInfos();
for (int i = 0; i != infos.length; i++)
{
if (infos[i].getContentType().equals(PKCSObjectIdentifiers.encryptedData))
{
PKCS12SafeBagFactory dataFact = new PKCS12SafeBagFactory(infos[i], inputDecryptorProvider);
PKCS12SafeBag[] bags = dataFact.getSafeBags();
assertEquals(1, bags.length);
assertEquals(PKCSObjectIdentifiers.keyBag, bags[0].getType());
assertTrue(Arrays.areEqual(privKey.getEncoded(), ((PrivateKeyInfo)bags[0].getBagValue()).getEncoded()));
Attribute[] attributes = bags[0].getAttributes();
assertEquals(1, attributes.length);
assertEquals(PKCSObjectIdentifiers.pkcs_9_at_friendlyName, attributes[0].getAttrType());
ASN1Encodable[] attrValues = attributes[0].getAttributeValues();
assertEquals(1, attrValues.length);
assertEquals(new DERBMPString("Eric's Key"), attrValues[0]);
}
else
{
fail("unknown bag encountered");
}
}
}