Skip to content

Commit

Permalink
Don't add padding to Base32
Browse files Browse the repository at this point in the history
  • Loading branch information
safris committed Jul 28, 2024
1 parent 2c37984 commit 55635e6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions otp/src/main/java/org/openjax/security/otp/GAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public final class GAuth {
public static String generateRandomSecretKey() {
final byte[] bytes = new byte[20];
random.nextBytes(bytes);
return Base32.encode(bytes);
return Base32.encode(bytes, false, true);
}

/**
Expand Down Expand Up @@ -74,7 +74,7 @@ public static String getBarCode(final String key, final String account, final St
*/
public static String getTOTPCode(final String key) {
final String normalizedKey = key.replace(" ", "").toUpperCase();
final byte[] bytes = Base32.decode(normalizedKey);
final byte[] bytes = Base32.decode(normalizedKey, false);
final long time = System.currentTimeMillis() / 1000 / 30;
final String hexTime = Long.toHexString(time);
return TOTP.generateTOTP(Hexadecimal.encode(bytes), hexTime, 6, Hmac.SHA1);
Expand Down

0 comments on commit 55635e6

Please sign in to comment.