public class PKCS12Writer extends CredentialWriter
Note: Export of a user private key from an Entrust digital identity to PKCS#12 is only permitted if PKCS#12 export is enabled for the digital identity (the 'entrustAllowPKCS12Export' role policy is set) and PKCS#12 export is enabled for the private key (the corresponding user certificate contains the 'PKCS12ExportPermission' extension or the 'entrustAllExportable' role policy is set).
| Modifier and Type | Field and Description |
|---|---|
static int |
ALL_KEYS
Key export mode indicating that all keys and associated certificates be
exported (includes key history).
|
static int |
ALL_LATEST_KEYS
Key export mode indicating that the latest key and associated certificate
in each certificate stream hould be exported (no key history).
|
static int |
DECRYPTION_KEY
Key export mode indicating the latest decryption key and encryption
certificate should be exported (no decryption key history).
|
static int |
SIGNING_AND_DECRYPTION_KEYS
Key export mode indicating both latest decryption and signing keys and
their associated certificates should be exported (no decryption key
history).
|
static int |
SIGNING_KEY
Key export mode indicating the latest signing key and verification
certificate should be exported.
|
| Constructor and Description |
|---|
PKCS12Writer(java.io.OutputStream outputStream,
int hashCount)
A constructor; creates a new
PKCS12Writer object used to
write a Digital Identity in the form of a PKCS#12 key file where the
latest key and certificate from each certificate stream is written. |
PKCS12Writer(java.io.OutputStream outputStream,
int keyExportMode,
int hashCount)
A constructor; creates a new
PKCS12Writer object used to
write a Digital Identity in the form of a PKCS#12 key file where the keys
and certificates that are written are controlled by the key export mode |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getType()
Returns the type, or name, of
CredentialWriter used to call
the method. |
void |
setCertificatesToExport(CertificateSet certificatesToExport)
Set the list of certificates to export when
User.write() is
called. |
void |
setExportCaCertificates(boolean exportCaCertificates)
Sets a flag indicating whether or not the CA certificate(s) associated
with the user's digital identity will be exported to PKCS12 during the
digital identity write operation.
|
void |
setFriendlyName(java.lang.String name,
boolean useKeyUsage)
This method is used to override the default Friendly Name used for the KeyBag
and Certificate Bags when exporting to the PKCS#12 format.
|
void |
setUseLegacyEcKeyFormat(boolean useLegacy)
Set a flag indicating if private elliptic curve (EC) keys should be
written out in a legacy format used by older toolkit versions or if the
standard PKCS8 encoding for EC private keys should be used.
|
addConfiguration, writePossiblepublic static final int SIGNING_KEY
public static final int DECRYPTION_KEY
public static final int SIGNING_AND_DECRYPTION_KEYS
public static final int ALL_LATEST_KEYS
public static final int ALL_KEYS
public PKCS12Writer(java.io.OutputStream outputStream,
int keyExportMode,
int hashCount)
PKCS12Writer object used to
write a Digital Identity in the form of a PKCS#12 key file where the keys
and certificates that are written are controlled by the key export mode
When exporting an Entrust User to PKCS#12 (from an EPF), the user's role policy must indicate "Allow PKCS#12 Export" is enabled (entrustAllowPKCS12Export - 1.2.840.113533.7.77); otherwise the write operation will fail.
One or more of a user's keys are written to the specified output stream.
Use the keyExportMode argument to specify the key, or keys,
to be exported. keyExportMode must be one of the following:
SIGNING_KEY the signing keyDECRYPTION_KEY the decryption keySIGNING_AND_DECRYPTION_KEYS the signing key and the
decryption keyALL_LATEST_KEYS the latest key from each certificate
streamALL_KEYS all keys (includes key history)Set the hash count to one of two values: 1, or 2000, unless you have specific reasons for setting a different hash count value.
If you plan to use the PKCS#12 file only with recent browsers (Netscape 4.5+, Internet Explorer 5.0+), or you just plan to read the file into the Toolkit, you should set the hash count to 2000. If you plan to use the PKCS#12 file in legacy browsers, you should set the hash count to 1.
outputStream - the output stream to the store the Digital Identity. This
stream will not be closed.keyExportMode - specifies the key to exporthashCount - specifies the number of hash iterations used to protect the
PKCS#12 filepublic PKCS12Writer(java.io.OutputStream outputStream,
int hashCount)
PKCS12Writer object used to
write a Digital Identity in the form of a PKCS#12 key file where the
latest key and certificate from each certificate stream is written.
For additional details, refer to
PKCS12Writer(OutputStream, int, int) when operated in the
ALL_LATEST_KEYS key export mode.
outputStream - the output stream to the store the Digital Identity. This
stream will not be closed.hashCount - specifies the number of hash iterations used to protect the
PKCS#12 filepublic java.lang.String getType()
CredentialWriter used to call
the method.getType in class CredentialWriterCredentialWriterpublic void setCertificatesToExport(CertificateSet certificatesToExport)
User.write() is
called.
This setting overrides any selection made by setting the export mode in the constructor.
certificatesToExport - The certificates to be exported.public void setUseLegacyEcKeyFormat(boolean useLegacy)
The default behaviour is to export EC keys using the standard PKCS8 encoding.
useLegacy - Set to true to use the legacy EC encoding format
that is compatible with older toolkit versions, or
false to use the standard PKCS8 encoding.EcPrivateKey.FORMAT_PKCS8_ENTRUST,
EcPrivateKey.FORMAT_PKCS8public void setExportCaCertificates(boolean exportCaCertificates)
By default, CA certificates (the user's CA certificate chain) are exported.
Warning: All Entrust digital identities require a root of trust;
if the CA certificate(s) are not exported to PKCS12 then the resulting
PKCS12 store cannot be logged into again using a User object
and a PKCS12Reader. Instead, the low-level PKCS12 utilities
classes found in the iaik.pkcs.pkcs12 package must be used
for accessing the keys and certificates in the PKCS12 store.
exportCaCertificates - true if the CA certificate(s) are to be exported
to the PKCS12 store; false otherwisepublic void setFriendlyName(java.lang.String name,
boolean useKeyUsage)
DN + KeyUsageFor example, if the User's DN is "cn=user,ou=myCompany,c=ca", and the KeyUsage for the Certificate is "Encryption" then by default the friendly name would become:
"cn=user,ou=myCompany,c=ca Encryption Certificate".If it were a Key, it would become:
"cn=user,ou=myCompany,c=ca Encryption key"This API overrides the default, and allows the user to specify any String value in place of the DN. If this API is called and null is passed in, the DN from the User's certificate will be used.
If the value of the useKeyUsage parameter is true, then the KeyUsage will be appended to the String part of the FriendlyName. If the value is false, the KeyUsage will not be added to the String part of the Friendly Name.
name - The Friendly Name to use for CertificateBag and KeyBags. This
overrides the default which is the User's DN.useKeyUsage - True to indicate the KeyUsage should be added to the Friendly Name,
false to indicate it should not be added to the FriendlyName.