OtpAuthUriBuilder

open class OtpAuthUriBuilder<S : OtpAuthUriBuilder<S>>(    type: String,     base32Secret: ByteArray,     removePaddingFromBase32Secret: Boolean = true,     charset: Charset = StandardCharsets.UTF_8)

A builder to create an OTP Auth URI as defined in Key Uri Format. This URI contains all necessary information for a TOTP/HOTP client to set up the code generation.

This URI can be used, for example, to be encoded into a QR code.

An example OTP Auth URI would be:

otpauth://totp/Company:John@company.com?secret=SGWY3DPESRKFPHH&issuer=Company&digits=8&algorithm=SHA1

Use the factory methods forTotp/TimeBasedOneTimePasswordGenerator.otpAuthUriBuilder or forHotp/HmacOneTimePasswordGenerator.otpAuthUriBuilder to create a/an TOTP/HOTP specific instance of an OtpAuthUriBuilder.

See also

Parameters

removePaddingFromBase32Secret

if set to true, the Base32 padding character = will be removed from the secret URI parameter (e.g., MFQWC=== will be transformed to MFQWC.), this is required by the specification.

Constructors

Link copied to clipboard
fun OtpAuthUriBuilder(    type: String,     base32Secret: ByteArray,     removePaddingFromBase32Secret: Boolean = true,     charset: Charset = StandardCharsets.UTF_8)

Types

Link copied to clipboard
object Companion
Link copied to clipboard
class Hotp(initialCounter: Long, base32Secret: ByteArray) : OtpAuthUriBuilder<OtpAuthUriBuilder.Hotp>

A builder for an HOTP OTP Auth URI.

Link copied to clipboard
class Totp(base32Secret: ByteArray) : OtpAuthUriBuilder<OtpAuthUriBuilder.Totp>

A builder for a TOTP OTP Auth URI.

Functions

Link copied to clipboard
fun algorithm(algorithm: HmacAlgorithm): S

Sets the algorithm query parameter, which is the uppercase name of the HMAC algorithms defined in HmacAlgorithm.

Link copied to clipboard
fun buildToByteArray(): ByteArray

Builds the final OTP Auth URI as a ByteArray.

Link copied to clipboard
fun buildToString(): String

Builds the final OTP Auth URI as a String.

Link copied to clipboard
fun buildToUri(): URI

Builds the final OTP Auth URI as a URI.

Link copied to clipboard
fun digits(digits: Int): S

Sets the digits query parameter, which is the length of the generated code.

Link copied to clipboard
fun issuer(issuer: String): S

Sets the issuer query parameter, which indicates the provider or service the account (for which the OTP code gets used) belongs to.

Link copied to clipboard
fun label(    accountName: String,     issuer: String?,     encodeSeparator: Boolean = false): S

Sets the label path part of the URI, which consist of an account name and an optional issuer. Both values will be separated by a colon (:), which can be URL encoded by setting the parameter encodeSeparator.

Inheritors

Link copied to clipboard
Link copied to clipboard