diff options
| author | Dan Ho <igaryhe@gmail.com> | 2019-03-14 08:16:24 +0800 |
|---|---|---|
| committer | Dan Ho <igaryhe@gmail.com> | 2019-03-14 08:16:24 +0800 |
| commit | b2eb150c0faff4cf1c1c3bc6c1da23695914d47f (patch) | |
| tree | e702aae7fff952af755be287c89a7913e707a63b /app/src/main/java/com/zeapo/pwdstore/utils/Otp.java | |
| parent | 6d909abde8990936cf446c72273d484c73172996 (diff) | |
| download | HardenedPass-b2eb150c0faff4cf1c1c3bc6c1da23695914d47f.tar.gz HardenedPass-b2eb150c0faff4cf1c1c3bc6c1da23695914d47f.zip | |
Read OTP digits, algorithm, period from uri, support Steam Guard
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/utils/Otp.java')
| -rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/utils/Otp.java | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/Otp.java b/app/src/main/java/com/zeapo/pwdstore/utils/Otp.java index 35e773e4..0bacd684 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/Otp.java +++ b/app/src/main/java/com/zeapo/pwdstore/utils/Otp.java @@ -12,17 +12,17 @@ import java.security.NoSuchAlgorithmException; import java.util.Arrays; public class Otp { - public static final int TIME_WINDOW = 30; - - private static final String ALGORITHM = "HmacSHA1"; - private static final int CODE_DIGITS = 6; private static final Base32 BASE_32 = new Base32(); private Otp() { } - public static String calculateCode(String secret, long counter) { + public static String calculateCode(String secret, long counter, String algorithm, String digits) { + String[] steam = {"2", "3", "4", "5", "6", "7", "8", "9", "B", "C", + "D", "F", "G", "H", "J", "K", "M", "N", "P", "Q", + "R", "T", "V", "W", "X", "Y"}; + String ALGORITHM = "Hmac" + algorithm.toUpperCase(); SecretKeySpec signingKey = new SecretKeySpec(BASE_32.decode(secret), ALGORITHM); Mac mac; @@ -42,6 +42,15 @@ public class Otp { byte[] code = Arrays.copyOfRange(digest, offset, offset + 4); code[0] = (byte) (0x7f & code[0]); String strCode = new BigInteger(code).toString(); - return strCode.substring(strCode.length() - CODE_DIGITS); + if (digits.equals("s")) { + String output = ""; + int bigInt = new BigInteger(code).intValue(); + for (int i = 0; i != 5; i++) { + output += steam[bigInt % 26]; + bigInt /= 26; + } + return output; + } + else return strCode.substring(strCode.length() - Integer.parseInt(digits)); } } |
