Poco::OSP::Auth::TwoFactor

class SecretGenerator

File Information

Library: OSP/Auth/TwoFactor
Package: TwoFactor
Header: Poco/OSP/Auth/TwoFactor/SecretGenerator.h

Description

This class generates a secret for HOTP/TOTP as described in RFC 4226.

The class also provides helper functions for generating a URI suitable for encoding in a QR code.

Member Summary

Member Functions: fromBase32, generate, toBase32, toURI

Constructors

SecretGenerator

SecretGenerator() = default;

Creates a SecretGenerator with the default secret length (128 bits).

SecretGenerator

explicit SecretGenerator(
    std::size_t secretLengthBits
);

Creates a SecretGenerator with the given secret length in bits. The length must be a multiple of 8. The secret length should be from 80 to 160 bits. Lengths shorter than 80 will be rejected.

Member Functions

fromBase32 static

static std::string fromBase32(
    const std::string & base32
);

Decodes the base32-encoded secret to a binary string.

generate

std::string generate() const;

Generates a new secret and returns it in a binary string.

toBase32 static

static std::string toBase32(
    const std::string & secret
);

Encodes a secret in Base32.

toURI static

static std::string toURI(
    const std::string & secret,
    const std::string & issuer,
    const std::string & account
);

Generates a URI suitable for displaying as a QR code.

See https://github.com/google/google-authenticator/wiki/Key-Uri-Format for more information.

Securely control IoT edge devices from anywhere   Connect a Device