Package com.amdelamar.jotp.type
Class TOTP
- java.lang.Object
-
- com.amdelamar.jotp.type.TOTP
-
- All Implemented Interfaces:
OTPInterface
public class TOTP extends java.lang.Object implements OTPInterface
Time based OTP class implements OTPInterface- Since:
- 1.0.0
- See Also:
- https://tools.ietf.org/html/rfc6238
-
-
Constructor Summary
Constructors Constructor Description TOTP()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringcreate(java.lang.String secret, java.lang.String base, int digits)Create a one-time-password with the given key, base, and digits.protected static java.lang.StringgenerateTotp(java.lang.String key, java.lang.String time, int digits, java.lang.String crypto)Generates a TOTP value for the given set of parameters.java.lang.StringgetLabel()protected static byte[]hexStringToBytes(java.lang.String hex)Converts a Hex based string to byte[]
-
-
-
Method Detail
-
getLabel
public java.lang.String getLabel()
- Specified by:
getLabelin interfaceOTPInterface
-
create
public java.lang.String create(java.lang.String secret, java.lang.String base, int digits) throws java.security.InvalidKeyException, java.security.NoSuchAlgorithmExceptionCreate a one-time-password with the given key, base, and digits.- Specified by:
createin interfaceOTPInterface- Parameters:
secret- The secret. Shhhhhh!base- The offset. (TOTP base is time from UTC rounded to the half-second)digits- The length of the code (Commonly '6')- Returns:
- code
- Throws:
java.security.NoSuchAlgorithmException- when HMAC is not available on this jvmjava.security.InvalidKeyException- when secret is invalid- See Also:
- https://tools.ietf.org/html/rfc6238
-
hexStringToBytes
protected static byte[] hexStringToBytes(java.lang.String hex)
Converts a Hex based string to byte[]- Parameters:
hex- the HEX string- Returns:
- byte array
-
generateTotp
protected static java.lang.String generateTotp(java.lang.String key, java.lang.String time, int digits, java.lang.String crypto) throws java.security.InvalidKeyException, java.security.NoSuchAlgorithmExceptionGenerates a TOTP value for the given set of parameters.- Parameters:
key- the shared secret, HEX encodedtime- a value that reflects a timedigits- number of digits to returncrypto- the crypto function to use- Returns:
- numeric String in base 10 that includes digits
- Throws:
java.security.NoSuchAlgorithmException- if hmac sha1 is not availablejava.security.InvalidKeyException- if given key is inappropriate for this mac
-
-