diff options
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/utils')
| -rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/utils/Otp.java (renamed from app/src/main/java/com/zeapo/pwdstore/utils/Totp.java) | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/Totp.java b/app/src/main/java/com/zeapo/pwdstore/utils/Otp.java index 5e4326e2..44e2aa64 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/Totp.java +++ b/app/src/main/java/com/zeapo/pwdstore/utils/Otp.java @@ -13,18 +13,18 @@ import java.util.Arrays; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; -public class Totp { +public class Otp { + public static final int TIME_WINDOW = 30; private static final String ALGORITHM = "HmacSHA1"; - private static final int TIME_WINDOW = 30; private static final int CODE_DIGITS = 6; private static final Base32 BASE_32 = new Base32(); - private Totp() { + private Otp() { } - public static String calculateCode(String secret, long epochSeconds) { + public static String calculateCode(String secret, long counter) { SecretKeySpec signingKey = new SecretKeySpec(BASE_32.decode(secret), ALGORITHM); Mac mac = null; @@ -39,8 +39,7 @@ public class Totp { return null; } - long time = epochSeconds / TIME_WINDOW; - byte[] digest = mac.doFinal(ByteBuffer.allocate(8).putLong(time).array()); + byte[] digest = mac.doFinal(ByteBuffer.allocate(8).putLong(counter).array()); int offset = digest[digest.length - 1] & 0xf; byte[] code = Arrays.copyOfRange(digest, offset, offset + 4); code[0] = (byte) (0x7f & code[0]); |
