* If the key string is improperly encoded.
*/
public static String computePin(String secret, Long counter) {
try {
final byte[] keyBytes = Base32String.decode(secret);
Mac mac = new HMac(new SHA1Digest());
mac.init(new KeyParameter(keyBytes));
PasscodeGenerator pcg = new PasscodeGenerator(mac);
if (counter == null) { // time-based totp
return pcg.generateTimeoutCode();
} else { // counter-based hotp
return pcg.generateResponseCode(counter.longValue());