Bouncy Castle Cryptography Library 1.85

org.bouncycastle.pkcs
Class PKCS12PfxPdu

java.lang.Object
  extended byorg.bouncycastle.pkcs.PKCS12PfxPdu

public class PKCS12PfxPdu
extends java.lang.Object

Holding class for a PKCS#12 PFX structure (RFC 7292). Supports MAC verification using the legacy PKCS#12 PBE-MAC and the PBMAC1 scheme introduced by RFC 9579.


Constructor Summary
PKCS12PfxPdu(byte[] pfx)
          Parse a BER/DER encoded PFX from a byte array.
PKCS12PfxPdu(org.bouncycastle.asn1.pkcs.Pfx pfx)
          Wrap an existing parsed PFX ASN.1 structure.
 
Method Summary
 org.bouncycastle.asn1.pkcs.ContentInfo[] getContentInfos()
          Return the content infos in the AuthenticatedSafe contained in this Pfx.
 byte[] getEncoded()
          Return the default (BER) encoding of the PFX.
 byte[] getEncoded(java.lang.String encoding)
          Return a Pfx with the outer wrapper encoded as asked for.
 org.bouncycastle.asn1.x509.AlgorithmIdentifier getMacAlgorithmID()
          Return the algorithm identifier describing the MAC algorithm
 boolean hasMac()
          Return whether or not there is MAC attached to this file.
 boolean isMacValid(PKCS12MacCalculatorBuilderProvider macCalcProviderBuilder, char[] password)
          Verify the MacData attached to the PFX is consistent with what is expected.
 org.bouncycastle.asn1.pkcs.Pfx toASN1Structure()
          Return the underlying ASN.1 object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PKCS12PfxPdu

public PKCS12PfxPdu(org.bouncycastle.asn1.pkcs.Pfx pfx)
Wrap an existing parsed PFX ASN.1 structure.

Parameters:
pfx - the PFX to wrap.

PKCS12PfxPdu

public PKCS12PfxPdu(byte[] pfx)
             throws java.io.IOException
Parse a BER/DER encoded PFX from a byte array.

Parameters:
pfx - the encoded PFX bytes.
Throws:
java.io.IOException - if the data is not a valid PFX encoding.
Method Detail

getContentInfos

public org.bouncycastle.asn1.pkcs.ContentInfo[] getContentInfos()
Return the content infos in the AuthenticatedSafe contained in this Pfx.

Returns:
an array of ContentInfo.

hasMac

public boolean hasMac()
Return whether or not there is MAC attached to this file.

Returns:
true if there is, false otherwise.

getMacAlgorithmID

public org.bouncycastle.asn1.x509.AlgorithmIdentifier getMacAlgorithmID()
Return the algorithm identifier describing the MAC algorithm

Returns:
the AlgorithmIdentifier representing the MAC algorithm, null if none present.

isMacValid

public boolean isMacValid(PKCS12MacCalculatorBuilderProvider macCalcProviderBuilder,
                          char[] password)
                   throws PKCSException
Verify the MacData attached to the PFX is consistent with what is expected.

Parameters:
macCalcProviderBuilder - provider builder for the calculator for the MAC
password - password to use
Returns:
true if mac data is valid, false otherwise.
Throws:
PKCSException - if there is a problem evaluating the MAC.
java.lang.IllegalStateException - if no MAC is actually present

toASN1Structure

public org.bouncycastle.asn1.pkcs.Pfx toASN1Structure()
Return the underlying ASN.1 object.

Returns:
a Pfx object.

getEncoded

public byte[] getEncoded()
                  throws java.io.IOException
Return the default (BER) encoding of the PFX.

Returns:
the encoded PFX bytes.
Throws:
java.io.IOException - if encoding fails.

getEncoded

public byte[] getEncoded(java.lang.String encoding)
                  throws java.io.IOException
Return a Pfx with the outer wrapper encoded as asked for. For example, Pfx is a usually a BER encoded object, to get one with DefiniteLength encoding use: getEncoded(ASN1Encoding.DL)

Parameters:
encoding - encoding style (ASN1Encoding.DER, ASN1Encoding.DL, ASN1Encoding.BER)
Returns:
a byte array containing the encoded object.
Throws:
java.io.IOException

Bouncy Castle Cryptography Library 1.85