phase4 uses Apache WSS4J (with theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/phax/phase4/llms.txt
Use this file to discover all available pages before exploring further.
Merlin provider) for WS-Security operations: signing, signature verification, encryption, and decryption. A crypto factory ties the key material to the AS4 stack.
There are two built-in crypto factory classes:
AS4CryptoFactoryConfiguration
Reads keystore and truststore paths and passwords from the global
application.properties. The simplest approach for a single, application-wide key pair.AS4CryptoFactoryInMemoryKeyStore
Receives an already-loaded
java.security.KeyStore object at construction time. Use this when you load keys programmatically, from a secrets manager, or need per-PMode key material.Configuration-file-based crypto factory
AS4CryptoFactoryConfiguration reads all key material from the active phase4 configuration (typically application.properties).
Required properties
All properties use the prefixorg.apache.wss4j.crypto.merlin. (the value of CAS4Crypto.DEFAULT_CONFIG_PREFIX).
Keystore properties
| Property (after prefix) | Required | Description |
|---|---|---|
keystore.type | No | Key store type. Default: JKS. Use PKCS12 for .p12 files. |
keystore.file | Yes | Classpath path or absolute file path to the key store. |
keystore.password | Yes | Password to open the key store. |
keystore.alias | Yes | Alias of the private key entry inside the key store. |
keystore.private.password | Yes | Password for the private key entry (often the same as keystore.password). |
Trust store properties
The trust store is optional. When omitted, the JRE default CA certificates (cacerts) are used.
| Property (after prefix) | Required | Description |
|---|---|---|
truststore.type | No | Trust store type. Default: JKS. Use PKCS12 for .p12 files. |
truststore.file | No | Classpath path or absolute file path to the trust store. |
truststore.password | No | Password to open the trust store. |
Example application.properties
Obtaining the default instance in code
Custom configuration prefix
If you need multiple key pairs (e.g., different prefixes for different PModes), pass a custom prefix:.).
In-memory keystore crypto factory
AS4CryptoFactoryInMemoryKeyStore accepts an already-loaded KeyStore. This is useful when you:
- Fetch credentials from a secrets manager at startup
- Load a key store from a byte array or database
- Need the key store loaded before the configuration system initializes
Using descriptor objects
The cleanest way is to build descriptor objects and hand them to the factory:Using a pre-loaded KeyStore directly
AS4KeyStoreDescriptor
AS4KeyStoreDescriptor is a static helper that reads key store configuration from a IConfigWithFallback object and produces a KeyStoreAndKeyDescriptor. It reads the following properties relative to the given prefix:
| Suffix | Description |
|---|---|
keystore.type | Key store type (JKS, PKCS12, …). Default: JKS. |
keystore.file | Path to the key store file. Mandatory. |
keystore.password | Key store password. Mandatory. |
keystore.alias | Alias of the private key entry. Mandatory. |
keystore.private.password | Private key password. Mandatory. |
null if any mandatory property is missing.
AS4TrustStoreDescriptor
AS4TrustStoreDescriptor is the equivalent helper for trust stores. It reads:
| Suffix | Description |
|---|---|
truststore.type | Trust store type (JKS, PKCS12, …). Default: JKS. |
truststore.file | Path to the trust store file. Mandatory (returns null if absent). |
truststore.password | Trust store password. Mandatory (returns null if absent). |
null if path or password are missing — in that case the JRE default CA certificates are used.
Per-PMode crypto factories
To use a different key pair for each P-Mode, implement theIAS4PModeAwareCryptoFactory interface. phase4 will call it with the active PMode and select the appropriate factory: