Generate Qr Code From Secret Key

16.12.2020by
Google authenticator (base32) and OATH (hex) TOTP QR code generator
From

QRCode Monkey is one of the most popular free online qr code generators with millions of already created QR codes. The high resolution of the QR codes and the powerful design options make it one of the best free QR code generators on the web that can be used for commercial and print purposes. /blood-bowl-player-key-generator.html. The solution is a QR code generator. Visit the page on your desktop and type the name, user and secret key, then point your mobile device at your monitor to scan the code into Google Authenticator (or whatever app you’re using to generate the six-digit codes). The Google Authenticator Setup QR code is generated based on a few things, one of these is the 'secret key', so depending on the codebase you are using to build it into your site the 'secret key' is normally generated first and that key is then used to generate the QR code.

gistfile1.txt
Key
#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Required packages (available from pip) : pyqrcode, pypng
importpyqrcode
importbase64
importos
importbinascii
#We want a secret of at least 30 hex chars for security reasons
SECRET_LEN=30
defconvert_secret_to_base32(secret):
returnbase64.b32encode(base64.b16decode(secret.upper()))
# Google authenticator format:
#otpauth://totp/[KEY NAME]?secret=[KEY SECRET, BASE 32].
#'Myphone nr' for example, but it can be anything, a login/uid, etc.
keyname='4155701111'
#if you want to generate a code for non-Google (ie standard OATH Hex secret):
#secret = binascii.b2a_hex(os.urandom(SECRET_LEN))
#For Google or Google-compatible authenticators:
secret=convert_secret_to_base32(binascii.b2a_hex(os.urandom(SECRET_LEN)))
#For HOTP, just replace totp by hotp ;-)
qrdata='otpauth://totp/{keyname}?secret={secret}'.format(keyname=keyname, secret=secret)
code=pyqrcode.create(qrdata)
# Generate on disk
code.png('code.png', scale=10)
# Generate in memory example:
# import io
# buffer = io.BytesIO()
# url.png(buffer)
# print('<img data='{}' />'.format(buffer.getvalue(())))

Generate Qr Code From Secret Keys

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment
Comments are closed.