Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Android compatibility #10

Merged
merged 1 commit into from
Jan 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/main/java/com/amdelamar/jotp/OTP.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.amdelamar.jotp.type.HOTP;
import com.amdelamar.jotp.type.TOTP;
import com.amdelamar.jotp.type.Type;
import org.apache.commons.codec.binary.Hex;

/**
* OTP (One Time Password) utility in Java. To enable two-factor authentication (2FA) using
Expand Down Expand Up @@ -82,7 +83,7 @@ public static String timeInHex(long timeInMillis) throws IOException {
byte[] longBytes = ByteBuffer.allocate(Long.SIZE / Byte.SIZE)
.putLong(time)
.array();
return org.apache.commons.codec.binary.Hex.encodeHexString(longBytes);
return new String(Hex.encodeHex(longBytes));
}

/**
Expand Down Expand Up @@ -112,7 +113,7 @@ public static String create(String secret, String base, int digits, Type type)

// convert Base32 secret to Hex
byte[] bytes = new org.apache.commons.codec.binary.Base32().decode(secret);
String key = org.apache.commons.codec.binary.Hex.encodeHexString(bytes);
String key = new String(Hex.encodeHex(bytes));

if (type == Type.HOTP) {
HOTP hotp = new HOTP();
Expand Down Expand Up @@ -161,7 +162,7 @@ public static boolean verify(String secret, String base, String code, int digits

// convert Base32 secret to Hex
byte[] bytes = new org.apache.commons.codec.binary.Base32().decode(secret);
String key = org.apache.commons.codec.binary.Hex.encodeHexString(bytes);
String key = new String(Hex.encodeHex(bytes));

// generate code to compare
String ncode = null;
Expand Down