Create a key pair on the CryptoHub
Perform the following two tasks to create a key pair:Set Futurex environment variables
Perform the following steps by using the pkcs11-tool available from the OpenSC ( github.com/OpenSC/OpenSC) suite to generate keys. On both DEB-based and RPM-based distributions, the package is calledopensc. In a terminal, run the following commands to set the requiredFXPKCS11 environment variables:Shell
Be sure to modify the file path to match the location of
libfxpkcs11.so and fxpkcs11.cfg on your system.Create a key pair
In a terminal, run the following command to create a new ECC key pair on the CryptoHub by using pkcs11-tool:Shell
fxpkcs11.cfg file.
If successful, the command output lists the keys that pkcs11-tool created on the CryptoHub.
Ansible Vault playbooks
In Ansible, playbooks perform automated tasks. You can reference the Futurex PKCS#11 library when performing these tasks inside the playbook file to perform various functions, including encrypting and decrypting files.Prerequisites
You must create a file for the Vault Password(such asvault_password_file.txt) and place it in the same directory with the other test files. This is the password that Ansible Vault uses to encrypt and decrypt the sample test file. Due to the importance of a password file, this file will be encrypted with a public key that is stored on CryptoHub.
In this example, we use a
vaultpasswordfile.txt because Ansible Vault typically requires the password to be supplied through a file or an executable script. This approach is essential for non-interactive automation and enables integration with HSM-based encryption workflows.Inventory file
An inventory file in Ansible defines the hosts that Ansible will manage. It can list IP addresses, hostnames, and groupings of machines, allowing you to organize and target them in playbooks. The file can be written in INI or YAML format. Example (INI format):Ini
local is targeted for local execution, common in test setups.
Example Directory Layout
Encrypt example
You must copy and paste the contents of this example into a file with the.yml extension and modify it as needed (such as encrypt.yml)
The following example file performs the following actions:
- Encrypts
test.txtusing Ansible Vault with the provided password file. Note:test.txtcan be a text file containing sample data. - Uses CryptoHub
's public key, which was generated earlier, to encryptvault_password_file.txt, storing the result invault_password_file.txt.enc. - Deletes the original, unencrypted
vault_password_file.txtto protect sensitive data. - Displays a success message if all tasks are completed successfully.
YAML
Shell
test.txt file will reveal that it is now encrypted by Ansible Vault, displaying content similar to:
None
Decrypt example
You must copy and paste the contents of this example into a file with the.yml extension and modify it as needed (such as decrypt.yml)
The following example performs the following actions
- Uses the CryptoHub**‘s private key** to decrypt
vault_password_file.txt.enc, restoring the original password into a temporary file. - Decrypts
test.txtusing Ansible Vault with the restored password file. - Deletes the temporary, decrypted password file after use to maintain security.
- Displays a success message if all tasks are completed successfully.
YAML
Shell

