Sample code for 30+ languages & platforms
PowerBuilder

Generate TOTP using Base32 Secret (6 Digits, Time-based, 30-second period)

See more Encryption Examples

Generates a 6-digit time-based TOTP code using a base32 secret with a 30-second time period.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Crypt
string ls_SecretKey
oleobject loo_SbKey
integer li_NumRemoved
integer li_NumDigits
integer li_TimePeriod

li_Success = 0

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// 
loo_Crypt = create oleobject
li_rc = loo_Crypt.ConnectToNewObject("Chilkat.Crypt2")
if li_rc < 0 then
    destroy loo_Crypt
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Base32 secret key:
ls_SecretKey = "oebf ytfl qmzb p4xd 2ztf zyz4 hjrw 3uyo"

loo_SbKey = create oleobject
li_rc = loo_SbKey.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_SbKey.Append(ls_SecretKey)

// Remove SPACE chars.
li_NumRemoved = loo_SbKey.Replace(" ","")

// Note: A new token is generated every 30 seconds.  You must generate within the same 30 second interval to get the same result.

// Generate 6 digits.
li_NumDigits = 6
// 30 second time period.
li_TimePeriod = 30
Write-Debug "Your token is: " + loo_Crypt.Totp(loo_SbKey.GetAsString(),"base32","0","",li_TimePeriod,li_NumDigits,-1,"sha1")


destroy loo_Crypt
destroy loo_SbKey