This document contains the help content for the ybdec
command-line program.
Command Overview:
Ybdec is a simple tool that can be used to encrypt and decrypt payloads using asymmetric PIV keys. It's uses P256 keys for HPKE encryption and decryption. The tool can be used as a building block in more advanced systems, for example, as a first factor for opening password managers or storing sensitive data.
Some of the commands require PIV credentials:
-
PIV Management key should be specified in YUBIKEY_MANAGEMENT_KEY variable as a hex encoded string. It is used for administrative operations like key generation and data writing. The default PIV management key is
010203040506070801020304050607080102030405060708
but it's highly recommended to change it. You can do this with yubikey-manager tool from Yubico. -
PIV PIN code should be specified in YUBIKEY_PIN variable as ASCII string. It's used for normal operations like decryption and sometimes data reading. The default YubiKey PIN is 123456 but it's highly recommended to change it.
Usage: ybdec <COMMAND>
generate
— Generate keypair. It will overwrite existing keypair so be careful!pubkey
— Export the public keyencrypt
— Encrypt payload to the public key using HPKEdecrypt
— Decrypt ECDH encrypted payload using the YubiKey keysstash
— Stash data to YubiKey PIV objectfetch
— Get data from YubiKey slot
Generate keypair. It will overwrite existing keypair so be careful!
The key type is P256 and it is always PIN protected.
Requires PIV management key in YUBIKEY_MANAGEMENT_KEY environment variable.
Usage: ybdec generate [OPTIONS]
-
--slot <SLOT>
— YubiKey PIV slotDefault value:
9d
-
--touch-policy <TOUCH_POLICY>
— Touch policy for the newly generated keyDefault value:
always
Possible values:
default
: Use the default touch policy for the slotnever
: A physical touch is NOT required to perform private key operationsalways
: A physical touch is required to perform any private key operations. The metal contact must be touched during each operation to ensure cardholder participationcached
: A physical touch is required to perform any private key operations. Each touch is cached for 15 seconds, during which time multiple private key operations may be performed without additional cardholder interaction. After 15 seconds the cached touch is cleared, and further operations require another physical touch
-
-o
,--output <OUTPUT>
— Where to save the public keyDefault value:
-
Export the public key.
On YubiKeys with firmware >= 5.3.0 this uses the metadata command which is available without PIN.
On older YubiKeys, it tries to recover public key using ECDH and ECDSA operations, so they require PIN in YUBIKEY_PIN environment variable.
The public key is printed in PEM format.
Usage: ybdec pubkey [OPTIONS]
-
--slot <SLOT>
— Which PIV slot to useDefault value:
9d
-
-o
,--output <OUTPUT>
— Where to save the public keyDefault value:
-
Encrypt payload to the public key using HPKE.
Requires PIN in YUBIKEY_PIN environment variable.
Usage: ybdec encrypt <--to-self [<TO_SELF>]|--to <TO>|--context <CONTEXT>|--input <INPUT>|--output <OUTPUT>>
-
--to-self <TO_SELF>
— Encrypt payload to the YubiKey itself. You can specify the slot, but by default the 9d is used -
--to <TO>
— Encrypt payload to the public key specified in file. The public key should be in PEM format -
--context <CONTEXT>
— Additional context for encryption. You must provide the same context for decryptionDefault value: ``
-
-i
,--input <INPUT>
— Plaintext path or-
for stdin. The encryption doesn't support streamingDefault value:
-
-
-o
,--output <OUTPUT>
— Ciphertext path or-
for stdout. The ciphertext is written in binary formatDefault value:
-
Decrypt ECDH encrypted payload using the YubiKey keys.
Requires PIN in YUBIKEY_PIN environment variable.
Usage: ybdec decrypt [OPTIONS]
-
--slot <SLOT>
— Slot to use for decryptionDefault value:
9d
-
--context <CONTEXT>
— Additional context for decryption. It should be the same as during encryptionDefault value: ``
-
-i
,--input <INPUT>
— Ciphertext path or-
for stdin. The decryption doesn't support streamingDefault value:
-
-
-o
,--output <OUTPUT>
— Plaintext path or-
for stdoutDefault value:
-
Stash data to YubiKey PIV object.
Requires PIV management key in YUBIKEY_MANAGEMENT_KEY environment variable.
Usage: ybdec stash [OPTIONS]
-
--slot <SLOT>
— The PIV object to use for stashingDefault value:
0x005FAEAD
-
-i
,--input <INPUT>
— Path to input data or-
for stdin. Maximum size for an object is ~3KbDefault value:
-
Get data from YubiKey slot.
Some slots require PIN in YUBIKEY_PIN environment variable. See The DataTags for more info.
Usage: ybdec fetch [OPTIONS]
-
--slot <SLOT>
— The PIV object to use for reading. Some objects require PIN. For more information, see The DataTags for more informationDefault value:
0x005FAEAD
-
-o
,--output <OUTPUT>
— Path to output data or-
for stdoutDefault value:
-
This document was generated automatically by
clap-markdown
.