Class TotpQrCode


public class TotpQrCode extends WQrCode
A QR code generator for TOTP secret keys.

This class can be used to generate a QR code from a TOTP secret key. The QR code will then be painted to the screen.

This allows for some authenticator apps to more conveniently add the TOTP secret key. This QR code embeds more than just the secret.

See Also:
  • Constructor Details

  • Method Details

    • formatKey

      public String formatKey(String key, String serviceName, String userName, int codeDigits)
      Format the key and other information to a correct QR code.

      To generate a correct QR code, it needs to follow a specific format. The rules of this format can be consulted on the site: https://github.com/google/google-authenticator/wiki/Key-Uri-Format.

      This stipulates that a valid string must contain a label, followed by some (optional) parameters.

      The label is formatted such that: serviceName:userName.

      The used parameters are:

      • secret: the generated TOTP secret key
      • issuer: same as the serviceName
      • userName: the name of the user for whom the QR code is created
      • algorithm: always SHA1 (the default)
      • digits: the number of digits the generated code contains
      • period: the size of the time frame/window