Skip to content

Commit ff01a4c

Browse files
committed
Renamed secretKey to key to avoid confusion.
1 parent a9c17e6 commit ff01a4c

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ final TimeBasedOneTimePasswordGenerator totp = new TimeBasedOneTimePasswordGener
1313
To actually generate time-based one-time passwords, you'll need a secret key and a timestamp. Secure key management is beyond the scope of this document; for the purposes of an example, though, we'll generate a random key:
1414

1515
```java
16-
final Key secretKey;
16+
final Key key;
1717
{
1818
final KeyGenerator keyGenerator = KeyGenerator.getInstance(totp.getAlgorithm());
1919

2020
// HMAC-SHA1 and HMAC-SHA256 prefer 64-byte (512-bit) keys; HMAC-SHA512 prefers 128-byte (1024-bit) keys
2121
keyGenerator.init(512);
2222

23-
secretKey = keyGenerator.generateKey();
23+
key = keyGenerator.generateKey();
2424
}
2525
```
2626

@@ -30,8 +30,8 @@ Armed with a secret key, we can deterministically generate one-time passwords fo
3030
final Date now = new Date();
3131
final Date later = new Date(now.getTime() + totp.getTimeStep(TimeUnit.MILLISECONDS));
3232

33-
System.out.format("Current password: %06d\n", totp.generateOneTimePassword(secretKey, now));
34-
System.out.format("Future password: %06d\n", totp.generateOneTimePassword(secretKey, later));
33+
System.out.format("Current password: %06d\n", totp.generateOneTimePassword(key, now));
34+
System.out.format("Future password: %06d\n", totp.generateOneTimePassword(key, later));
3535
```
3636

3737
…which produces (for one randomly-generated key):

src/test/java/com/eatthepath/otp/ExampleApp.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@ public class ExampleApp {
3131
public static void main(final String[] args) throws NoSuchAlgorithmException, InvalidKeyException {
3232
final TimeBasedOneTimePasswordGenerator totp = new TimeBasedOneTimePasswordGenerator();
3333

34-
final Key secretKey;
34+
final Key key;
3535
{
3636
final KeyGenerator keyGenerator = KeyGenerator.getInstance(totp.getAlgorithm());
3737

3838
// SHA-1 and SHA-256 prefer 64-byte (512-bit) keys; SHA512 prefers 128-byte (1024-bit) keys
3939
keyGenerator.init(512);
4040

41-
secretKey = keyGenerator.generateKey();
41+
key = keyGenerator.generateKey();
4242
}
4343

4444
final Date now = new Date();
4545
final Date later = new Date(now.getTime() + totp.getTimeStep(TimeUnit.MILLISECONDS));
4646

47-
System.out.format("Current password: %06d\n", totp.generateOneTimePassword(secretKey, now));
48-
System.out.format("Future password: %06d\n", totp.generateOneTimePassword(secretKey, later));
47+
System.out.format("Current password: %06d\n", totp.generateOneTimePassword(key, now));
48+
System.out.format("Future password: %06d\n", totp.generateOneTimePassword(key, later));
4949
}
5050
}

0 commit comments

Comments
 (0)