e-CryptIt Engine Xojo Plugin

Einhugur_2FA_TOTP.GenerateValue Method

Generates 6 digit value from given secret key and current time and also returns how many seconds are remaining of the 30 second window. This variation generates value for standard implementation.

shared GenerateValue(
   secretKey as String,
   ByRef secondsRemaining as Integer) as String

Parameters

secretKey
The secret key.

Secret keys are represented in various of ways and the plugin will preprocess them correctly to take all representations.

For example then all of the following keys are equal:
N7P7TWR3Q5WUA2XG
N7P7 TWR3 Q5WU A2XG
n7P7 tWR3 q5WU a2XG
secondsRemaining (ByRef parameter)
ByRef parameter which returns how many seconds are remaining of the 30 second window.

Returns

String
6 digit number.

Remarks

This function can throw InvalidArgumentException.

Some authentication apps only support the standard implementation while more advanced apps support customised setup.


try
    var outSecondsRemaining as Integer
    var pin as String = Einhugur_2FA_TOTP.GenerateValue(tbSecretKey.Text, outSecondsRemaining)
   
    tbPinValue.Text = pin
    tbTimeRemaining.Text = outSecondsRemaining.ToString()
   
catch e as InvalidArgumentException
// We can get exception if passing in empty secret or invalid secret.
MessageBox(e.Message)
end try


See Also

Einhugur_2FA_TOTP Class