Hardware-backed file encryption using YubiKey and TPM 2.0
YubiKey-Encrypt provides unbreakable file encryption by combining:
- TPM 2.0 hardware random number generation
- YubiKey challenge-response authentication
- AES-256-CBC encryption
- Automatic cloud backup support
Your files remain encrypted at rest, requiring physical possession of your YubiKey to decrypt.
- 🔐 Hardware-backed security (no passwords to remember)
- 🎲 TPM-generated cryptographic challenges
- 🔑 YubiKey challenge-response authentication
- ☁️ Automatic backup to Dropbox/Google Drive
- 🔄 Multi-YubiKey support for redundancy
- 🗑️ Secure memory handling (uses /dev/shm)
- YubiKey with challenge-response configured in slot 2
- TPM 2.0 chip (standard on most modern laptops)
- Linux with tpm2-tools installed
- OpenSSL
- yubikey-manager (ykman)
# Install dependencies
sudo apt install tpm2-tools yubikey-manager openssl
# Clone repository
git clone https://github.com/yourusername/yubikey-encrypt
cd yubikey-encrypt
# Make scripts executable
chmod +x yubikey-encrypt.sh yubikey-decrypt.shConfigure challenge-response in slot 2:
# Generate new secret
ykman otp chalresp -2 --touch --generate
# Or set specific secret (for backup YubiKey)
ykman otp chalresp -2 --touch [your-hex-secret]# Basic encryption
./yubikey-encrypt.sh secret.txt
# With cloud backup
./yubikey-encrypt.sh -c dropbox secret.txt
# Custom output name
./yubikey-encrypt.sh -o backup.enc secret.txt# Local file
./yubikey-decrypt.sh secret.txt.enc challenge.bin
# From cloud
./yubikey-decrypt.sh dropbox:secret.txt.enc
# With specific YubiKey (multi-key setup)
./yubikey-decrypt.sh -k aes_key.yubikey2 secret.txt.enc challenge.binFor redundancy with multiple YubiKeys:
- Configure different secrets on each YubiKey
- Use the multi-key encryption script:
./encrypt-multi-yubikey.sh wallet.dat
# Follow prompts to encrypt with each YubiKeyEither YubiKey can then decrypt the files independently.
- Challenge Generation: TPM generates 32 bytes of hardware randomness
- Key Derivation: YubiKey transforms challenge into AES key via HMAC-SHA1
- Encryption: OpenSSL encrypts file with derived key using AES-256-CBC
- Storage: Encrypted file + challenge saved (challenge is public, safe to store)
- Something you have: Physical YubiKey required
- Hardware-backed: Keys never exist in software
- Tamper-resistant: YubiKey locks after 8 wrong attempts
- Quantum-resistant: AES-256 provides 128-bit quantum security
./yubikey-encrypt.sh -c dropbox wallet.dat
# Creates: wallet.dat.enc, challenge.bin
# Backs up to: ~/Dropbox/yubikey-encrypted/tar -czf backup.tar.gz important-files/
./yubikey-encrypt.sh backup.tar.gz
rm backup.tar.gz # Original can be deleted# Add to crontab
0 2 * * * /path/to/yubikey-encrypt.sh -c gdrive /home/user/documents.tar"No YubiKey present"
- Ensure YubiKey is inserted
- Check USB connection
- Verify with:
ykman list
"YubiKey core error"
- Slot 2 not configured:
ykman otp info - Configure with:
ykman otp chalresp -2 --generate
"TPM error"
- Check TPM enabled in BIOS
- Verify with:
ls /dev/tpm* - May need:
sudo usermod -a -G tss $USER
MIT License - See LICENSE file
Pull requests welcome! Please ensure:
- Scripts pass shellcheck
- Documentation updated
- Tested on Ubuntu/Debian
- Keep
challenge.binwith encrypted files (both needed for decryption) - YubiKey secret cannot be extracted
- Lost YubiKey = lost data (use multi-key setup for critical files)
- No backdoors - even we cannot decrypt your files
Created for secure credential storage in the Brunnen-G project.