Synchronous one-time password (OTP) algorithms generate short-lived numeric codes based on a shared secret credential provisioned during the activation process. The HID Approve SDK supports the two main standards HOTP (HMAC-Based One-Time Password) and TOTP (Time-Based One-Time Password).
HOTP is defined in RFC 4226 and produces a new code each time a counter increments, requiring the client and server to stay synchronized on that counter.
TOTP is defined in RFC 6238 and derives the code from the current time (typically in 30-second intervals), eliminating the need for a shared counter.
Example Code:
do{ // Find keys available for the usage OTP; if several are available, we need to distinguish them with their labels let filter = HIDApproveKeyFilter(keyUsage: .OTP) if let keys = try self.getContainer()?.findKeys(filter: [filter]) { for key in keys { // To identify the protection policy used : look at the type of the protectionPolicy. // HIDApprovePolicyType.Device : no password required // HIDApprovePolicyType.Password : password required // HIDApprovePolicyType.BioPassword : see the protection policy documentation for usage. let policyType = try key.getProtectionPolicy().type let algo = key.algorithm let label = try key.getProperty(propertyId: .LABEL) NSLog("Found key: PolicyType=%@, Algorithm=%@, Label=%@", policyType.description, algo, label) } let key = keys.first let otpGenerator = try key?.getDefaultOTPGenerator() // Get the next OTP // We assume the generator is Synchronous (HOTP or TOTP algorithms) // We assume the key is not password protected (password nil) let syncOtpGenerator = otpGenerator as! HIDApproveSyncOTPGenerator let otp = try syncOtpGenerator.getOTP(password: nil) }}catch let error as NSError{ NSLog("Failed to generate OTP: %@",error.localizedDescription);}