mirror of https://github.com/beemdevelopment/Aegis
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
771 B
Java
26 lines
771 B
Java
package me.impy.aegis.crypto;
|
|
|
|
public class OTP {
|
|
private OTP() {
|
|
}
|
|
|
|
public static String generateOTP(KeyInfo info) throws Exception {
|
|
String otp;
|
|
|
|
switch (info.getType()) {
|
|
case "totp":
|
|
String time = Long.toHexString(System.currentTimeMillis() / 1000 / info.getPeriod());
|
|
otp = TOTP.generateTOTP(info.getSecret(), time, info.getDigits(), info.getAlgorithm());
|
|
break;
|
|
case "hotp":
|
|
otp = HOTP.generateOTP(info.getSecret(), info.getCounter(), info.getDigits(), false, -1);
|
|
break;
|
|
default:
|
|
// this should never happen
|
|
throw new Exception("unsupported type");
|
|
}
|
|
|
|
return otp;
|
|
}
|
|
}
|