|
| | TimeBasedOTP () |
| |
| | TimeBasedOTP (String algorithm, int numberDigits, int timeIntervalInSeconds, int lookAheadWindow) |
| |
| String | generateTOTP (String secretKey) |
| |
| boolean | validateTOTP (String token, byte[] secret) |
| |
| void | setCalendar (Calendar calendar) |
| |
| String | generateHOTP (String key, int counter) |
| |
| int | validateHOTP (String token, String key, int counter) |
| |
| String | generateOTP (String key, String counter, int returnDigits, String crypto) |
| |
TOTP: Time-based One-time Password Algorithm Based on http://tools.ietf.org/html/draft-mraihi-totp-timebased-06
- 著者
- anil saldhana
- から
- Sep 20, 2010
◆ TimeBasedOTP() [1/2]
| org.keycloak.models.utils.TimeBasedOTP.TimeBasedOTP |
( |
| ) |
|
|
inline |
static final int DEFAULT_NUMBER_DIGITS
Definition: HmacOTP.java:34
static final int DEFAULT_DELAY_WINDOW
Definition: TimeBasedOTP.java:33
static final int DEFAULT_INTERVAL_SECONDS
Definition: TimeBasedOTP.java:32
static final String DEFAULT_ALGORITHM
Definition: HmacOTP.java:33
◆ TimeBasedOTP() [2/2]
| org.keycloak.models.utils.TimeBasedOTP.TimeBasedOTP |
( |
String |
algorithm, |
|
|
int |
numberDigits, |
|
|
int |
timeIntervalInSeconds, |
|
|
int |
lookAheadWindow |
|
) |
| |
|
inline |
- 引数
-
| algorithm | the encryption algorithm |
| numberDigits | the number of digits for tokens |
| timeIntervalInSeconds | the number of seconds a token is valid |
| lookAheadWindow | the number of previous intervals that should be used to validate tokens. |
49 this.
clock =
new Clock(timeIntervalInSeconds);
final int lookAheadWindow
Definition: HmacOTP.java:39
final int numberDigits
Definition: HmacOTP.java:38
Clock clock
Definition: TimeBasedOTP.java:35
final String algorithm
Definition: HmacOTP.java:37
◆ generateHOTP()
| String org.keycloak.models.utils.HmacOTP.generateHOTP |
( |
String |
key, |
|
|
int |
counter |
|
) |
| |
|
inlineinherited |
59 String steps = Integer.toHexString(counter).toUpperCase();
62 while (steps.length() < 16)
String generateOTP(String key, String counter, int returnDigits, String crypto)
Definition: HmacOTP.java:100
final int numberDigits
Definition: HmacOTP.java:38
final String algorithm
Definition: HmacOTP.java:37
◆ generateOTP()
| String org.keycloak.models.utils.HmacOTP.generateOTP |
( |
String |
key, |
|
|
String |
counter, |
|
|
int |
returnDigits, |
|
|
String |
crypto |
|
) |
| |
|
inlineinherited |
This method generates an OTP value for the given set of parameters.
- 引数
-
| key | the shared secret, HEX encoded |
| counter | a value that reflects a time |
| returnDigits | number of digits to return |
| crypto | the crypto function to use |
- 戻り値
- A numeric String in base 10 that includes return digits
- 例外
-
| java.security.GeneralSecurityException | |
101 String result = null;
107 while (counter.length() < 16)
108 counter =
"0" + counter;
115 byte[] k = key.getBytes();
120 int offset = hash[hash.length - 1] & 0xf;
122 int binary = ((hash[offset] & 0x7f) << 24) | ((hash[offset + 1] & 0xff) << 16) | ((hash[offset + 2] & 0xff) << 8)
123 | (hash[offset + 3] & 0xff);
127 result = Integer.toString(otp);
129 while (result.length() < returnDigits) {
130 result =
"0" + result;
byte [] hmac_sha1(String crypto, byte[] keyBytes, byte[] text)
Definition: HmacOTP.java:147
byte [] hexStr2Bytes(String hex)
Definition: HmacOTP.java:170
static final int [] DIGITS_POWER
Definition: HmacOTP.java:36
◆ generateSecret()
| static String org.keycloak.models.utils.HmacOTP.generateSecret |
( |
int |
length | ) |
|
|
inlinestaticinherited |
48 String chars =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW1234567890";
49 SecureRandom r =
new SecureRandom();
50 StringBuilder sb =
new StringBuilder();
51 for (
int i = 0; i < length; i++) {
52 char c = chars.charAt(r.nextInt(chars.length()));
◆ generateTOTP()
| String org.keycloak.models.utils.TimeBasedOTP.generateTOTP |
( |
String |
secretKey | ) |
|
|
inline |
Generates a token.
- 引数
-
| secretKey | the secret key to derive the token from. |
60 String steps = Long.toHexString(T).toUpperCase();
63 while (steps.length() < 16)
String generateOTP(String key, String counter, int returnDigits, String crypto)
Definition: HmacOTP.java:100
final int numberDigits
Definition: HmacOTP.java:38
Clock clock
Definition: TimeBasedOTP.java:35
long getCurrentInterval()
Definition: TimeBasedOTP.java:109
final String algorithm
Definition: HmacOTP.java:37
◆ setCalendar()
| void org.keycloak.models.utils.TimeBasedOTP.setCalendar |
( |
Calendar |
calendar | ) |
|
|
inline |
Clock clock
Definition: TimeBasedOTP.java:35
void setCalendar(Calendar calendar)
Definition: TimeBasedOTP.java:119
◆ validateHOTP()
| int org.keycloak.models.utils.HmacOTP.validateHOTP |
( |
String |
token, |
|
|
String |
key, |
|
|
int |
counter |
|
) |
| |
|
inlineinherited |
- 引数
-
- 戻り値
- -1 if not a match. A positive number means successful validation. This positive number is also the new value of the counter
78 int newCounter = counter;
79 for (newCounter = counter; newCounter <= counter +
lookAheadWindow; newCounter++) {
81 if (candidate.equals(token)) {
82 return newCounter + 1;
final int lookAheadWindow
Definition: HmacOTP.java:39
String generateHOTP(String key, int counter)
Definition: HmacOTP.java:58
◆ validateTOTP()
| boolean org.keycloak.models.utils.TimeBasedOTP.validateTOTP |
( |
String |
token, |
|
|
byte [] |
secret |
|
) |
| |
|
inline |
Validates a token using a secret key.
- 引数
-
| token | OTP string to validate |
| secret | Shared secret |
- 戻り値
80 String steps = Long.toHexString(currentInterval - i).toUpperCase();
83 while (steps.length() < 16)
88 if (candidate.equals(token)) {
final int lookAheadWindow
Definition: HmacOTP.java:39
String generateOTP(String key, String counter, int returnDigits, String crypto)
Definition: HmacOTP.java:100
final int numberDigits
Definition: HmacOTP.java:38
Clock clock
Definition: TimeBasedOTP.java:35
long getCurrentInterval()
Definition: TimeBasedOTP.java:109
final String algorithm
Definition: HmacOTP.java:37
◆ algorithm
| final String org.keycloak.models.utils.HmacOTP.algorithm |
|
protectedinherited |
◆ clock
| Clock org.keycloak.models.utils.TimeBasedOTP.clock |
|
private |
◆ DEFAULT_ALGORITHM
| final String org.keycloak.models.utils.HmacOTP.DEFAULT_ALGORITHM = HMAC_SHA1 |
|
staticinherited |
◆ DEFAULT_DELAY_WINDOW
| final int org.keycloak.models.utils.TimeBasedOTP.DEFAULT_DELAY_WINDOW = 1 |
|
static |
◆ DEFAULT_INTERVAL_SECONDS
| final int org.keycloak.models.utils.TimeBasedOTP.DEFAULT_INTERVAL_SECONDS = 30 |
|
static |
◆ DEFAULT_NUMBER_DIGITS
| final int org.keycloak.models.utils.HmacOTP.DEFAULT_NUMBER_DIGITS = 6 |
|
staticinherited |
◆ HMAC_SHA1
| final String org.keycloak.models.utils.HmacOTP.HMAC_SHA1 = "HmacSHA1" |
|
staticinherited |
◆ HMAC_SHA256
| final String org.keycloak.models.utils.HmacOTP.HMAC_SHA256 = "HmacSHA256" |
|
staticinherited |
◆ HMAC_SHA512
| final String org.keycloak.models.utils.HmacOTP.HMAC_SHA512 = "HmacSHA512" |
|
staticinherited |
◆ lookAheadWindow
| final int org.keycloak.models.utils.HmacOTP.lookAheadWindow |
|
protectedinherited |
◆ numberDigits
| final int org.keycloak.models.utils.HmacOTP.numberDigits |
|
protectedinherited |
このクラス詳解は次のファイルから抽出されました:
- D:/AppData/doxygen/keycloak/src/keycloak/src/main/java/org/keycloak/models/utils/TimeBasedOTP.java