@Test public void testGenerateSHA512() { final byte[] key = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4' }; try { final TOTPGenerator totp = new TOTPGenerator(key, TOTPGenerator.Mode.SHA512, 8); assertEquals("90693936", totp.generate(59)); assertEquals("25091201", totp.generate(1111111109)); assertEquals("99943326", totp.generate(1111111111)); assertEquals("93441116", totp.generate(1234567890)); assertEquals("38618901", totp.generate(2000000000)); assertEquals("47863826", totp.generate(20000000000L)); } catch (InvalidKeyException e) { fail("SHA512 test key is invalid."); } }
public String generate(long time) { long counter = (time - startTime) / timeStep; byte[] hash = getHMAC(Longs.toByteArray(counter)); int offset = hash[hash.length - 1] & 0xF; int binary = ((hash[offset] & 0x7F) << 24) | ((hash[offset + 1] & 0xFF) << 16) | ((hash[offset + 2] & 0xFF) << 8) | (hash[offset + 3] & 0xFF); return toCode(binary, length); }
TOTPGenerator { public String generate(long time) { long counter = (time - startTime) / timeStep; byte[] hash = getHMAC(Longs.toByteArray(counter)); int offset = hash[hash.length - 1] & 0xF; int binary = ((hash[offset] & 0x7F) << 24) | ((hash[offset + 1] & 0xFF) << 16) | ((hash[offset + 2] & 0xFF) << 8) | (hash[offset + 3] & 0xFF); return toCode(binary, length); } }
TOTPGenerator { public String generate(long time) { long counter = (time - startTime) / timeStep; byte[] hash = getHMAC(Longs.toByteArray(counter)); int offset = hash[hash.length - 1] & 0xF; int binary = ((hash[offset] & 0x7F) << 24) | ((hash[offset + 1] & 0xFF) << 16) | ((hash[offset + 2] & 0xFF) << 8) | (hash[offset + 3] & 0xFF); return toCode(binary, length); } TOTPGenerator(byte[] key, Mode mode, int length, long startTime,
            long timeStep);  TOTPGenerator(byte[] key, Mode mode, int length); }
TOTPGenerator { public String generate(long time) { long counter = (time - startTime) / timeStep; byte[] hash = getHMAC(Longs.toByteArray(counter)); int offset = hash[hash.length - 1] & 0xF; int binary = ((hash[offset] & 0x7F) << 24) | ((hash[offset + 1] & 0xFF) << 16) | ((hash[offset + 2] & 0xFF) << 8) | (hash[offset + 3] & 0xFF); return toCode(binary, length); } TOTPGenerator(byte[] key, Mode mode, int length, long startTime,
            long timeStep);  TOTPGenerator(byte[] key, Mode mode, int length); String generate(long time); String generate(); String previous(long time); String previous(); }
TOTPGenerator { public String generate(long time) { long counter = (time - startTime) / timeStep; byte[] hash = getHMAC(Longs.toByteArray(counter)); int offset = hash[hash.length - 1] & 0xF; int binary = ((hash[offset] & 0x7F) << 24) | ((hash[offset + 1] & 0xFF) << 16) | ((hash[offset + 2] & 0xFF) << 8) | (hash[offset + 3] & 0xFF); return toCode(binary, length); } TOTPGenerator(byte[] key, Mode mode, int length, long startTime,
            long timeStep);  TOTPGenerator(byte[] key, Mode mode, int length); String generate(long time); String generate(); String previous(long time); String previous(); static final long DEFAULT_START_TIME; static final long DEFAULT_TIME_STEP; }