totp

command module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2023 License: MIT Imports: 1 Imported by: 0

README

TOTP

Install

go install github.com/richardjennings/totp

About

Implementation of the TOTP Time-Based One-Time Password Algorithm RFC 6238 which is an extension of HOTP RFC 4226 with support for Google Authenticator Key Uri Format and otpauth-migration links.

Features

  • Generate TOTP codes and export as otpauth QR Code PNG images.
  • Generate TOTP codes from Google Authenticator otpauth-migration export links.
  • Convert Google Authenticator otpauth-migration export links into otpauth links.
  • Generate TOTP codes from otpauth links.
  • Generate TOTP codes from base32 encoded secrets, e.g. as provided by GitHub
  • Create otpauth-migration links from otpauth links.
  • Import otpauth links into Keychain.
  • Generate TOTP codes from Keychain.

Usage Examples

Create a TOTP code, otpauth link and QR Code PNG image:

$ totp gen --timestamp 10000 --digits=6 --issuer=myorg --label=totp@myorg --secret=somesecret --qr-png qr.png       
otpauth://totp/totp@myorg?algorithm=SHA1&digits=6&issuer=myorg&period=30&secret=ONXW2ZLTMVRXEZLU
473009

qr.png

Import otpauth links from otpauth-migration Google Authenticator backup:

$ totp otpmigrate --link "otpauth-migration://offline?data=CiUKCnNvbWVzZWNyZXQSCnRvdHBAbXlvcmcaBW15b3JnIAEoATACEAEYASAA"
otpauth://totp/totp@myorg?algorithm=SHA1&digits=6&issuer=myorg&period=30&secret=J5HFQVZSLJGFITKWKJMEKWSMKU

Generate a code from an otpauth URI:

$ totp otpauth --timestamp 10000  "otpauth://totp/totp@myorg?algorithm=SHA1&digits=6&issuer=myorg&period=30&secret=ONXW2ZLTMVRXEZLU" 
totp@myorg 473009

Generate a code from a GitHub TOTP base32 encoded shared secret

$ totp gen --secret "thesharedsecret"
otpauth://totp?algorithm=SHA1&digits=6&period=30&secret=thesharedsecret
123456

Create a TOTP code programmatically:

    package main
    
    import (
    	"github.com/richardjennings/totp/pkg/totp"
    	"fmt"
    )
    func main() {
    	opts := totp.Opts{
    		Timestep:           30,
    		InitialCounterTime: 0,
    		Secret:             []byte("12345678901234567890"),
    		Digits:             8,
    		Algorithm:          totp.SHA1,
    		CurrentUnixTime:    59,
    	}
    	fmt.Println(totp.GenerateTOTP(opts)) // 94287082
    }

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
example
pkg
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL