Generating QR code of very big file?

9,550

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.

Share:
9,550

Related videos on Youtube

toogley
Author by

toogley

Updated on September 18, 2022

Comments

  • toogley
    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
      Admin about 8 years
      Remove <, the command is qrencode -o test.png -t png "$( cat private.key)"
    • Admin
      Admin about 8 years
      @cuonglm sry, didn't realize that mistake. I updated my answer.
    • Admin
      Admin about 8 years
      i have updated my answer
    • Admin
      Admin about 8 years
      are 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
      Admin about 8 years
      @Theophrastus i just found it out myself.
  • toogley
    toogley about 8 years
    Sry, 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
    geruetzel about 8 years
    Yes and even this limit does not apply to your key - see my answer's update!
  • Admin
    Admin about 8 years
    This 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
    Admin over 5 years
    Why do you specify the dpi in the qrencode command? I'm curious what purpose that serves. Is it necessary?
  • Admin
    Admin over 5 years
    Just 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 to 1000 on the split operation and just generate a few more QR codes. Then it scans like a dream.
  • ccpizza
    ccpizza about 2 years
    the problem with the generated qr codes is that they are too dense and phones don't seem to be able to parse them