Skip to main content
This section uses Java keytool to generate a new key pair and a self-signed Android APK signing certificate directly on the CryptoHub. On FXPKCS11 6.0 rev dc27 or later, this single command generates the key pair on the appliance and produces a usable PrivateKeyEntry with no CryptoHub UI step. You then list the keystore to confirm the private key and certificate are present. These steps ensure that you can use APKSigner and the self-signed certificate to sign an APK file in the next section.
The JDK installation includes the keytool application, so you can run the keytool commands in this section with no additional configuration.

Generate a key pair

Perform the following steps to generate a key pair and Android APK signing certificate on the CryptoHub:
1
Export FXPKCS11_CFG so the Futurex PKCS #11 library can locate its configuration file (fxpkcs11.cfg). Point it at the fxpkcs11.cfg you configured in Install and configure Futurex PKCS #11:
Shell
On Windows, set FXPKCS11_CFG as a machine-wide variable with setx instead (see Configure SunPKCS11 to use the Futurex PKCS11 module). If you set fxpkcs11.cfg in its default location, this step is not required.
2
Execute the following command, passing the pkcs11.cfg file you created in the previous section with -providerArg. The -dname value sets the certificate subject (its Common Name), and the -ext flags add the code-signing extensions:
Text
The keytool application generates the key pair on the CryptoHub and self-signs a certificate for it. With no -storepass on the command line, keytool prompts for the KeyStore password.
3
When prompted for the KeyStore password, enter the CryptoHub identity password (PKCS #11 PIN) configured inside the <CRYPTO-OPR-PASS> tag in the fxpkcs11.cfg file.

Verifying the Private Key and Certificate in the Java Keystore

Run the following keytool command on the device that will be signing APKs to confirm the key pair generated on the CryptoHub and lists a PrivateKeyEntry. The -providerArg flag passes the pkcs11.cfg file you created in the previous section:
Shell
When prompted for the keystore password, enter the identity password configured inside the <CRYPTO-OPR-PASS> tag in the fxpkcs11.cfg file.
If the command succeeds, you should see an output similar to the following:
None
Important: Take note of the on-token alias (in this example, apksignerdemo-1784141140:apksignerdemo) of the entry, as that is needed for the signing command in the next section.
The CryptoHub assigns the on-token key its own alias in the form <alias>-<id>:<alias> (for example, apksignerdemo-1784141140:apksignerdemo), where <id> is generated per key and is not deterministic. This alias, not the short -alias value you passed to keytool -genkeypair, is what apksigner must reference. Copy the exact alias from this keytool -list output for the --ks-key-alias argument in the signing command in the next section.