Skip to content

CLI Commands Reference

Installation

shell
dotnet tool install -g Cocoar.Configuration.Secrets.Cli

All commands are invoked as cocoar-secrets <command>.

encrypt

Encrypt a value and set it at a property path in a JSON file.

shell
cocoar-secrets encrypt --file <path> --path <property-path> --cert <cert-path> [options]
OptionAliasTypeDefaultDescription
--file-fstringrequiredPath to the JSON configuration file
--path-pstringrequiredProperty path (e.g. Database:ConnectionString)
--cert-cstringrequiredPath to the PFX certificate file
--value-vstringPlaintext value to encrypt. If omitted, encrypts the existing value at the path
--password-pwdstringCertificate password (prompts if not provided)
--kidstring"default"Key identifier for the certificate
--createboolfalseCreate the JSON file if it doesn't exist

Examples:

shell
# Encrypt a connection string
cocoar-secrets encrypt \
  --file appsettings.json \
  --path "Database:ConnectionString" \
  --value "Server=prod;Database=mydb;Password=secret" \
  --cert cert.pfx \
  --kid "prod-2026"

# Encrypt from stdin (avoids shell history)
echo -n "my-secret-value" | cocoar-secrets encrypt \
  --file appsettings.json \
  --path "ApiKeys:Stripe" \
  --cert cert.pfx

# Encrypt existing plaintext value in-place
cocoar-secrets encrypt \
  --file appsettings.json \
  --path "Database:ConnectionString" \
  --cert cert.pfx

decrypt

Decrypt an encrypted value from a JSON file.

shell
cocoar-secrets decrypt --file <path> --path <property-path> --cert <cert-path> [options]
OptionAliasTypeDefaultDescription
--file-fstringrequiredPath to the JSON configuration file
--path-pstringrequiredProperty path of the encrypted value
--cert-cstringrequiredPath to the PFX certificate file
--password-pwdstringCertificate password (prompts if not provided)
--replaceboolfalseReplace the encrypted value with plaintext in the file

WARNING

--replace modifies the file irreversibly. The encrypted envelope is replaced with the plaintext value.

Examples:

shell
# Display decrypted value (read-only)
cocoar-secrets decrypt \
  --file appsettings.json \
  --path "Database:ConnectionString" \
  --cert cert.pfx

# Replace encrypted value with plaintext in-place
cocoar-secrets decrypt \
  --file appsettings.json \
  --path "Database:ConnectionString" \
  --cert cert.pfx \
  --replace

generate-cert

Generate a self-signed certificate for encryption.

shell
cocoar-secrets generate-cert --output <path> [options]
OptionAliasTypeDefaultDescription
--output-ostringrequiredOutput path for certificate file(s)
--password-pwdstringPassword for PFX file (omit for password-less)
--format-fmtstring"auto"Output format: pfx, pem, or auto (infer from extension)
--subject-sstring"CN=Cocoar Secrets"Certificate subject
--valid-yearsint1Validity period in years
--key-sizeint2048RSA key size (2048, 3072, or 4096)
--overwriteboolfalseOverwrite existing file without prompt

Examples:

shell
# Generate a password-less PFX certificate
cocoar-secrets generate-cert --output certs/config.pfx

# Generate a PEM certificate with custom subject
cocoar-secrets generate-cert \
  --output certs/config.pem \
  --subject "CN=My App Secrets" \
  --valid-years 5 \
  --key-size 4096

TIP

Password-less certificates are recommended. Protect them with file permissions instead:

  • Windows: icacls cert.pfx /inheritance:r /grant:r "YourUser:(R)"
  • Linux/macOS: chmod 600 cert.pfx

convert-cert

Convert a certificate between PFX and PEM formats.

shell
cocoar-secrets convert-cert --input <path> --output <path> [options]
OptionAliasTypeDefaultDescription
--input-istringrequiredInput certificate file
--output-ostringrequiredOutput certificate file
--input-password--ipassstringPassword for input PFX file
--output-password--opassstringPassword for output PFX file (omit for password-less)
--format-fstring"auto"Output format: pfx, pem, or auto
--overwriteboolfalseOverwrite existing output file(s)

Examples:

shell
# Convert password-protected PFX to password-less PFX
cocoar-secrets convert-cert \
  --input cert.pfx \
  --ipass "OldPassword" \
  --output cert-nopwd.pfx

# Convert PFX to PEM
cocoar-secrets convert-cert \
  --input cert.pfx \
  --output cert.pem

cert-info

Display detailed information about a certificate.

shell
cocoar-secrets cert-info --input <path> [options]
OptionAliasTypeDefaultDescription
--input-istringrequiredCertificate file path (PFX or PEM)
--password-pwdstringCertificate password (if password-protected)

Output includes:

  • Certificate details: Subject, Issuer, Serial Number, Thumbprint
  • Validity: Not Before, Not After, status (Valid/Expired/Not yet valid)
  • Key information: Algorithm, Key Size, Private Key presence, Password protection
  • File information: Size, format, timestamps

Example:

shell
cocoar-secrets cert-info --input certs/config.pfx

Exit Codes

All commands use consistent exit codes:

CodeMeaning
0Success
1Argument error
2I/O error (file not found, permission denied)
3Cryptographic error (wrong certificate, corrupt data)
4General error

Encryption Details

All commands use the same encryption scheme:

PurposeAlgorithm
Key wrappingRSA-OAEP-SHA256
Data encryptionAES-256-GCM

The encrypted value is stored as a JSON envelope with fields: type, version, kid, alg, wk, walg, iv, ct, tag.

Released under the Apache-2.0 License.