mirror of https://github.com/beemdevelopment/Aegis
Added OTP.java
This class wraps the TOTP and HOTP functions in a method called generateOTP which takes an instance of KeyInfo.pull/41/head
parent
d4007ab065
commit
6a6da66bbe
@ -0,0 +1,25 @@
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue