certz convert -- Reference

May 2, 2026 ยท View on GitHub

Convert certificates between PEM, DER, and PFX formats with automatic input format detection. Certificates are format-agnostic, but platforms are not. This command handles all the common conversion paths without memorising complex flag combinations.

See also: Certificate Formats


Simplified Syntax

certz convert <input> --to <format> [options]
Argument / OptionDescription
<input>Input certificate file. Format is auto-detected.
--to, -tTarget format: pem, der, or pfx (required).
--output, -oOutput file path. Default: same directory as input, new extension.
--keyPrivate key file. Required when converting to PFX if the input has no embedded key.
--password, -pPassword for PFX input or output.
--password-fileRead the PFX password from a file (avoids shell history exposure).
--pfx-encryptionPFX encryption mode: modern (default, AES-256-CBC) or legacy (3DES).
--include-keyWhether to extract the private key alongside the certificate (default: true).
--repasswordRe-encrypt a PFX file with a new password (always uses modern AES-256-CBC encryption).
--new-password, --npNew password for PFX re-encryption. Auto-generated if omitted.
--dry-run, --drDetect the input format and show what output would be produced, without writing any files.
--guided, -gLaunch the interactive wizard. Prompts for input file, target format, output path, and password.
--formatOutput format: text (default) or json.

Format Auto-Detection

certz determines the input format from the file extension first, then falls back to reading the file content for ambiguous extensions.

ExtensionDetected format
.pfx, .p12PFX (PKCS#12)
.derDER (binary ASN.1)
.pemPEM (Base64 text)
.crt, .cerAuto-detect from file content
.keyAuto-detect from file content

Content detection rules:

  • File starts with -----BEGIN -> PEM
  • File is binary and parses as PKCS#12 -> PFX
  • File is binary but not PKCS#12 -> DER

Output File Naming

When --output is not specified, the output file is placed in the same directory as the input with a new extension:

Input--toDefault output
server.pfxpemserver.pem + server.key
server.pempfxserver.pfx
server.pemderserver.der
server.derpemserver.pem
server.derpfxserver.pfx
server.pfxderserver.der

When converting to PEM and a private key is extracted, the key is written to a separate .key file next to the certificate file.


Conversion Examples

PFX to PEM

Extracts the certificate and private key into separate files:

certz convert server.pfx --to pem --password secret
# Creates: server.pem, server.key

certz convert server.pfx --to pem --password secret --output /certs/server.pem
# Creates: /certs/server.pem, /certs/server.key

# Certificate only, no key file
certz convert server.pfx --to pem --password secret --include-key:false

PEM to PFX

# Auto-discovers server.key in the same directory
certz convert server.pem --to pfx

# Explicit key file
certz convert server.pem --to pfx --key private.key --password MyPass

# Auto-generated password (printed to console)
certz convert server.pem --to pfx --key private.key

PEM to DER

certz convert server.pem --to der
# Creates: server.der

certz convert server.pem --to der --output /tmp/server-binary.der

DER to PEM

certz convert server.der --to pem
# Creates: server.pem

certz convert server.der --to pem --output decoded.pem

PFX to DER

certz convert server.pfx --to der --password secret
# Creates: server.der (certificate only, no key)

DER to PFX

DER files do not contain a private key, so --key is required:

certz convert server.der --to pfx --key server.key --password NewPass
# Creates: server.pfx

Certificate-only extraction

Omit the key from PFX output when you only need the public certificate:

certz convert server.pfx --to pem --password secret --include-key:false

PFX Encryption

When certz produces a PFX file, it encrypts it with AES-256-CBC by default (modern PKCS#12 encryption introduced in RFC 9579). Use --pfx-encryption legacy when the target system cannot read AES-256 PFX files.

ModeAlgorithmWhen to use
modern (default)AES-256-CBC, HMAC-SHA256, 100 000 iterationsAll modern platforms
legacy3DES (RC2-40 outer, SHA-1 HMAC)Older Java (pre-JDK 8u301), some legacy Windows APIs
# Default: modern encryption
certz convert cert.pem --to pfx --key cert.key

# Legacy 3DES for old Java versions
certz convert cert.pem --to pfx --key cert.key --pfx-encryption legacy

Why modern? Java's default keytool now reads AES-256 PFX. The legacy flag exists only for environments that pre-date that support.


Platform Deployment Matrix

For each platform, the table shows the required certificate format, the certz command that produces it, and any steps needed after the conversion.

PlatformRequired formatcertz commandPost-certz notes
IISPFX (.pfx)certz convert cert.pem --to pfx --key cert.keyImport via IIS Manager or certutil -importpfx
nginxPEM cert + PEM key (separate files)certz convert cert.pfx --to pem --password passSet ssl_certificate and ssl_certificate_key in nginx.conf
Apache httpdPEM cert + PEM key (separate files)certz convert cert.pfx --to pem --password passSet SSLCertificateFile and SSLCertificateKeyFile
Tomcat (Java)PFX / PKCS#12certz convert cert.pem --to pfx --key cert.keyReference with certificateKeystoreFile in <SSLHostConfig>
Java keytool / JKSPFX first, then keytoolcertz convert cert.pem --to pfx then keytool -importkeystoreSee JKS note below
Kubernetes TLS SecretPEM cert + PEM keycertz create dev app.local --pipe | kubectl create secret tls ...Pipe mode avoids intermediate files
macOS KeychainPFX (.p12)certz convert cert.pem --to pfx --key cert.keyDouble-click .p12 or use security import cert.p12
Azure App ServicePFXcertz convert cert.pem --to pfx --key cert.keyUpload via Azure portal or az webapp config ssl upload
HAProxyPEM cert + key concatenatedcertz convert cert.pfx --to pem then cat cert.pem cert.key > combined.pemPoint HAProxy bind directive at combined.pem

JKS note

Java KeyStore (.jks) is not a direct certz output target. Convert to PFX first, then use keytool to import:

# Step 1: convert to PFX
certz convert cert.pem --to pfx --key cert.key --output cert.pfx --password mypass

# Step 2: import into JKS with keytool (bundled with every JDK)
keytool -importkeystore \
  -srckeystore cert.pfx -srcstoretype PKCS12 -srcstorepass mypass \
  -destkeystore keystore.jks -deststoretype JKS -deststorepass changeit

JSON Output Schema

Use --format json to get machine-readable output suitable for CI/CD pipelines.

certz convert server.pem --to pfx --key server.key --format json

Example output:

{
  "success": true,
  "subject": "CN=server.local",
  "outputFormat": "PFX",
  "outputFile": "server.pfx",
  "additionalOutputFiles": null,
  "inputCertificate": "/path/to/server.pem",
  "inputKey": "/path/to/server.key",
  "inputPfx": null,
  "generatedPassword": "Xk9!mP2rLq",
  "passwordWasGenerated": true
}

Field descriptions:

FieldTypeDescription
successbooltrue if conversion succeeded
subjectstringSubject DN from the converted certificate
outputFormatstring"PEM", "DER", or "PFX"
outputFilestringPath to the primary output file
additionalOutputFilesstring[] or nullAdditional files produced (e.g. .key alongside .pem)
inputCertificatestring or nullSource PEM/DER file path, if applicable
inputKeystring or nullSource key file path, if applicable
inputPfxstring or nullSource PFX file path, if applicable
generatedPasswordstring or nullAuto-generated PFX password, if no password was supplied
passwordWasGeneratedbooltrue if certz generated the password

PFX Password Change

The --repassword flag re-encrypts a PFX file with a new password in a single command. The private key never touches disk in unencrypted form. Output always uses modern AES-256-CBC encryption, automatically upgrading legacy 3DES-encrypted PFX files.

# Change password (explicit new password)
certz convert server.pfx --repassword --password oldpass --new-password newpass

# Change password (auto-generated, printed to console)
certz convert server.pfx --repassword --password oldpass

# Write to a new file instead of overwriting
certz convert server.pfx --repassword --password oldpass --new-password newpass --output server-new.pfx

# Save generated password to file
certz convert server.pfx --repassword --password oldpass --password-file server.password

Constraints:

  • --repassword and --to are mutually exclusive
  • Input must be a PFX file (auto-detected)
  • --password is required to decrypt the existing PFX

Troubleshooting

ProblemLikely causeFix
"Wrong password" on PFX inputIncorrect --password valueVerify the password with certz inspect cert.pfx --password ... first
"Private key not found"PEM to PFX conversion with no key availableAdd --key private.key; or ensure <name>.key is in the same directory
"Legacy Java cannot read PFX"Java version predates AES-256 PKCS#12 supportAdd --pfx-encryption legacy to produce a 3DES-encrypted PFX
"Output file already exists"Auto-named output collides with an existing fileUse --output to specify a distinct path
"Unable to detect format"Ambiguous extension with unexpected contentRename the file with the correct extension (.pem, .der, .pfx)
Input and output format are the same--to value matches the detected input formatNo conversion needed; if in doubt, run certz inspect <file> to confirm the format