Generating QR code of very big file?
Solution 1
Your error message already gives a hint as to what's wrong!
Your one-liner is providing the actual file content as filename to the qrencode program. Hence the error message.
Try qrencode -o test.png -t png < private.key
.
You should take a look at shell input-output redirection. For example, I/O Redirection.
I see that you too have found your way to the developers GitHub repository of qrencode :) There is an explanation why a 4096-bit key cannot be encoded as a QR code:
qrencode is encoding your private GPG key as 8 bit (binary|utf-8), because the key is not pure alphanumeric. It contains special character. the alphanumeric mode only supports those special character .(%*+-./:). So the maximum GPG key can only be 2953 char long.
From https://github.com/fukuchi/libqrencode/issues/31
Solution 2
If you pass the options -Sv40
(40 is a version), qrencode
will automatically create multiple images for input that's too large. For example:
qrencode -o private.png -t png -Sv 40 < private.key
will output private-01.png
, private-02.png
, and private-03.png
.
Solution 3
I just found out that this is not possible.
% wc -c ~/private.key
6709 /home/toogley/private.key
(-c
counts characters.)
to cite from wikipedia:
max characters for alphanumerical characters: 4,296.
Solution 4
I suggest that you minimize your key before encoding it.
gpg --export --export-options export-minimal
Depending on how you've used your key in the past, it may save you old binding signatures.
Solution 5
You may be interested in paperkey, which is designed to take a GPG secret key, and transform it into a sequence of bytes that can be printed out on paper. The secret key can be subsequently recovered from the text after scanning it or keying it in.
There's also a discussion of various ways of archiving data on paper which you might find interesting.
Related videos on Youtube
![toogley](https://i.stack.imgur.com/nIDkp.png?s=256&g=1)
toogley
Updated on September 18, 2022Comments
-
toogley almost 2 years
I want to generate a QR code of my 4096-bit armored GPG private key. The key is so big, the program
qrencode
seems to fail because of its size.$ gpg --export-secret-keys --armor > ~/private.key $ ./qrencode -o test.png < ~/private.key
Result:
Failed to encode the input data: Numerical result out of range
How can I make that happen? Are there alternative programs to qrencode which can handle a very big GPG key? I want to print it on paper as this security.SE question suggested.
The comments of @geruetzel and @ cuonglm are addressing this version of my question.
-
Admin about 8 yearsRemove
<
, the command isqrencode -o test.png -t png "$( cat private.key)"
-
Admin about 8 years@cuonglm sry, didn't realize that mistake. I updated my answer.
-
Admin about 8 yearsi have updated my answer
-
Admin about 8 yearsare you coming up against the designed size limit for QR codes? consider searching down to "Maximum character storage capacity" on the wikipedia page: en.wikipedia.org/wiki/QR_code
-
Admin about 8 years@Theophrastus i just found it out myself.
-
-
toogley about 8 yearsSry, i didn't realize it that - but still It seems that my gpg key is too big for Qrencode. (I updated my answer to address that issue)
-
geruetzel about 8 yearsYes and even this limit does not apply to your key - see my answer's update!
-
Admin about 8 yearsThis is what I was thinking also, why not split the key into three pieces, then create three qr codes that can be scanned and reassembled.
-
Admin over 5 yearsWhy do you specify the dpi in the
qrencode
command? I'm curious what purpose that serves. Is it necessary? -
Admin over 5 yearsJust FYI for future readers,
2500
might be sufficiently small to generate the a QR code, but a QR code that dense is very hard to scan with a phone. It's probable that you can still read it by taking a picture and running it through a command line utility like those found in the arch aur but most android apps will have trouble with it. It's not too much more work to set the byte limit to1000
on thesplit
operation and just generate a few more QR codes. Then it scans like a dream. -
ccpizza about 2 yearsthe problem with the generated qr codes is that they are too dense and phones don't seem to be able to parse them