This guide assumes your Product Admin has already created a Signer and assigned you to it. If the signer has an approval policy, you’ll also need active access before signing.
apksigner with the Infisical PKCS#11 module. Since apksigner is a Java-based tool, it uses the same SunPKCS11 provider approach as jarsigner.
Prerequisites
- A Signer created by your Product Admin
- Active signing access (if an approval policy is attached)
- A machine identity added to the Signer
- The Infisical PKCS#11 module installed and configured
- Android SDK Build Tools 30.0.0 or later (includes
apksigner)
Step 1: Set Up Authentication
Configure the Infisical PKCS#11 module with your machine identity credentials. Without this, the signing commands below fail with an auth error. Create/etc/infisical/pkcs11.conf (or set INFISICAL_PKCS11_CONFIG to point elsewhere):
Environment variables override values from the config file.
Step 2: Create the SunPKCS11 Provider Configuration
Create a configuration file for Java’s SunPKCS11 provider. Save it asinfisical-pkcs11.cfg:
On macOS, use
.dylib. On Windows, use .dll. If you have multiple signers and need a specific one, add slot = 0 (replace with the correct slot index).Step 3: Sign an APK
Useapksigner with the PKCS#11 provider:
--ks NONE: Required when using PKCS#11 (no file-based keystore).--ks-type PKCS11: Tells apksigner to use the PKCS#11 provider.--ks-key-alias: The signer name (token label in PKCS#11).--out: Writes the signed APK to a new file. Without this flag,apksignermodifies the APK in place.
Signing an Android App Bundle (AAB)
For AAB files, usejarsigner instead of apksigner since AAB signing follows the JAR signing format:
Step 4: Verify the Signature
Verify the signed APK. If you signed in place (without--out), verify the same file. If you used --out, verify the output file:
CI/CD Integration
Example for a Gradle-based Android project in CI:Troubleshooting
For any issue, enable debug logging in your config file ("log_level": "debug", "log_file": "/tmp/infisical-pkcs11.log") to get detailed output.
Failed to load signer or key alias not found
Failed to load signer or key alias not found
Ensure the
--provider-class is sun.security.pkcs11.SunPKCS11, the --provider-arg points to a valid config file, and the --ks-key-alias matches your signer name exactly.APK signature scheme v2/v3 not applied
APK signature scheme v2/v3 not applied
Use
apksigner (not jarsigner) for APK signing. Only apksigner applies v2/v3 APK signature schemes.What’s Next?
Sign JARs
Sign Java artifacts with jarsigner
Sign Windows Binaries
Sign Windows executables with osslsigncode