Transferring sensitive data over Bluetooth, Wi‑Fi, or cloud services can expose it to eavesdropping or accidental leaks. QR codes are a air‑gapped medium: the data never touches a network, and the visual nature makes it easy to verify that you are scanning the exact image you generated. By combining QR codes with strong AES‑256 encryption in Termux, you get a portable, offline method that works on any Android phone—even those that lack root access.
If you are new to Termux, think of it as a lightweight Linux terminal that runs inside Android. All commands below are typed inside the Termux console.
Termux. Install it.pkg update && pkg upgrade -y
pkg install openssl qrencode coreutils -y
openssl provides the encryption utilities, qrencode creates QR images, and coreutils gives us split and cat.
~/storage/downloads folder automatically:
pkg install termux-api -y
After installation, grant Termux access to your shared storage so you can read the file you want to send and write the received one:
termux-setup-storage
You will be prompted to allow storage access – accept it.
We will use symmetric encryption (a single secret) because it is fast and easy for one‑off transfers. The secret will be a 32‑byte (256‑bit) random key stored in a file that you keep private on the sending device.
enc_key.bin:
openssl rand -out enc_key.bin 32
xxd -p enc_key.bin > enc_key.hex
enc_key.bin to a safe place (e.g., a password manager or a secure note). You will need the exact same file on the receiving device to decrypt.Why keep the key separate? If the QR codes are intercepted, they contain only ciphertext. Without the key, the data remains unreadable.
Assume the file you want to send is /sdcard/Download/secret.pdf. The workflow is:
openssl enc -aes-256-cbc -salt -in /sdcard/Download/secret.pdf \
-out secret.enc -pass file:enc_key.bin
base64 secret.enc > secret.b64
split -b 1800 secret.b64 part_
This creates files named part_aa, part_ab, … each containing a fragment of the encoded data.
At this point you have a series of part_?? files ready to be turned into QR images.
We will use qrencode to create PNG images. The -l H flag selects the highest error‑correction level (30 % data recovery), which is useful when scanning from a phone screen.
mkdir qr_codes
part_?? into a PNG:
for f in part_*; do
qrencode -l H -t PNG -o qr_codes/${f}.png -r $f
done
The -r option tells qrencode to read the raw file content directly.
qr_codes folder – you should see a series of PNG files named part_aa.png, part_ab.png, etc.Now you have a visual set of QR codes that can be displayed on the sender’s screen, projected onto a wall, or saved and shared via any image‑friendly app. Because the data is encrypted, the QR codes themselves are safe to show publicly.
On the target phone, open your preferred QR‑code scanner. Make sure it can copy the raw text (most scanners do). Follow these steps:
touch received.b64
received.b64. In many scanners you can tap “Copy” after each scan; then in Termux run:
termux-clipboard-get >> received.b64
If your scanner writes directly to a file, you can skip the clipboard step.
aa, ab, …). If you miss one, the final file will be corrupted.When you finish, received.b64 should be roughly the same size as the original secret.b64 on the sender.
Now we reverse the preparation steps:
base64 -d received.b64 > received.enc
enc_key.bin you generated on the sender (copy it securely to the receiver first – e.g., via a QR code of the hex representation, or via a trusted USB‑OTG transfer):
openssl enc -d -aes-256-cbc -in received.enc -out decrypted.pdf \
-pass file:enc_key.bin
sha256sum on both devices, compare checksums:
sha256sum secret.pdf # on sender
sha256sum decrypted.pdf # on receiver
Identical hashes confirm a successful transfer.
That’s it – you now have the original file on the receiving phone, never having exposed it to a network.
If the file is small (< 1 KB after encryption), you can skip the chunking step and generate a single QR code:
openssl enc -aes-256-cbc -salt -in myfile.txt -out myfile.enc -pass file:enc_key.bin
base64 myfile.enc | qrencode -l H -t PNG -o single_qr.png
Scanning the single QR directly yields the Base64 string, which you can decode and decrypt as shown earlier.
-l H (already used) and ensure the display is bright and the phone camera is steady. Reduce the chunk size to 1500 bytes if the scanner still fails.01|, 02|) and later sort the file before concatenation.enc_key.bin on the receiver matches the sender’s key (compare the hex dump). Remember that the key file is binary – copying it via a text‑only channel will corrupt it.termux-setup-storage and accept the prompt. If the problem persists, uninstall and reinstall Termux.enc_key.bin for multiple transfers. Generate a fresh key each time to enforce forward secrecy.shred -u enc_key.bin (install coreutils for shred).openssl enc -pbkdf2) if you cannot safely transfer a binary key file.-pass file:enc_key.bin with -pass pass:YourStrongPassword. Remember that passwords are easier to guess, so use a high‑entropy phrase.qr‑send.sh that takes a file path, encrypts, splits, and generates QR images in one command. Likewise, a qr‑receive.sh can collect scanned chunks into a file and decrypt automatically./sdcard/Download with the actual mount point (e.g., /storage/XXXX-XXXX). Ensure Termux has permission via termux-setup-storage.By following the steps above you have created a completely offline, end‑to‑end encrypted file‑transfer workflow that leverages only free, open‑source tools available on any Android phone. The process is transparent: you control the encryption key, you see exactly what data is being encoded, and you avoid any third‑party cloud or network that could compromise privacy.
Feel free to adapt the script snippets to your own workflow – for example, integrating QR generation into a Termux shortcut or automating the scan‑append step with termux-camera-photo and zbarimg. The core idea remains the same: encrypt, encode, split, scan, reassemble, decrypt. With this knowledge you can securely exchange passwords, confidential PDFs, or any small file without ever touching the internet.









