Search in sources :

Example 1 with BcPKCS12MacCalculatorBuilderProvider

use of org.bouncycastle.pkcs.bc.BcPKCS12MacCalculatorBuilderProvider in project vcert-java by Venafi.

the class PEMCollectionTest method toPkcs12.

@Test
void toPkcs12() throws VCertException, IOException, GeneralSecurityException, PKCSException {
    String body = readResourceAsString("certificates/certWithKey.pem");
    PEMCollection pemCollection = PEMCollection.fromStringPEMCollection(body, ChainOption.ChainOptionIgnore, null, null);
    byte[] pkcs12Data = pemCollection.toPkcs12(PKCS12_PASSWORD);
    PKCS12PfxPdu pfx = new PKCS12PfxPdu(pkcs12Data);
    assertThat(pfx.isMacValid(new BcPKCS12MacCalculatorBuilderProvider(BcDefaultDigestProvider.INSTANCE), PKCS12_PASSWORD.toCharArray())).isTrue();
    ContentInfo[] infos = pfx.getContentInfos();
    assertThat(infos.length).isEqualTo(1);
    assertThat(infos[0].getContentType()).isEqualTo(PKCSObjectIdentifiers.encryptedData);
}
Also used : BcPKCS12MacCalculatorBuilderProvider(org.bouncycastle.pkcs.bc.BcPKCS12MacCalculatorBuilderProvider) ContentInfo(org.bouncycastle.asn1.pkcs.ContentInfo) PKCS12PfxPdu(org.bouncycastle.pkcs.PKCS12PfxPdu) Test(org.junit.jupiter.api.Test)

Aggregations

ContentInfo (org.bouncycastle.asn1.pkcs.ContentInfo)1 PKCS12PfxPdu (org.bouncycastle.pkcs.PKCS12PfxPdu)1 BcPKCS12MacCalculatorBuilderProvider (org.bouncycastle.pkcs.bc.BcPKCS12MacCalculatorBuilderProvider)1 Test (org.junit.jupiter.api.Test)1