Skip to content

Commit

Permalink
Divide output from key generator into 4 symbol blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
pspacek committed Apr 18, 2014
1 parent bbf7213 commit b9986db
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main/java/org/jboss/totp/TOTPMIDlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ private static String base32Encode(final byte[] bytes) {
if (bytes == null) {
return "";
}
int i = 0, index = 0, digit = 0;
int i = 0, index = 0, digit = 0, outchars = 0;
int currByte, nextByte;
StringBuffer base32 = new StringBuffer((bytes.length + 7) * 8 / 5);

Expand All @@ -956,6 +956,9 @@ private static String base32Encode(final byte[] bytes) {
i++;
}
base32.append(BASE32_CHARS.charAt(digit));
outchars++;
if (outchars % 4 == 0)
base32.append(" ");
}

return base32.toString();
Expand Down Expand Up @@ -1029,10 +1032,12 @@ private static String toHexString(byte[] data, int offset, int length) {
if (data == null || data.length == 0)
return "";

final StringBuffer s = new StringBuffer(length * 2);
final StringBuffer s = new StringBuffer(length * 3);
for (int i = offset; i < offset + length; i++) {
s.append(HEX_TABLE[(data[i] & 0xf0) >>> 4]);
s.append(HEX_TABLE[(data[i] & 0x0f)]);
if ((i - offset) % 2 == 1)
s.append(" ");
}
return s.toString();
}
Expand Down

0 comments on commit b9986db

Please sign in to comment.