Created
April 25, 2016 03:49
-
-
Save asaph/19291ed93730ac49601708f8657e244d to your computer and use it in GitHub Desktop.
Create the data string for the Google Authenticator QR Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String getGoogleAuthenticatorBarCode(String secretKey, String account, String issuer) { | |
String normalizedBase32Key = secretKey.replace(" ", "").toUpperCase(); | |
try { | |
return "otpauth://totp/" | |
+ URLEncoder.encode(issuer + ":" + account, "UTF-8").replace("+", "%20") | |
+ "?secret=" + URLEncoder.encode(normalizedBase32Key, "UTF-8").replace("+", "%20") | |
+ "&issuer=" + URLEncoder.encode(issuer, "UTF-8").replace("+", "%20"); | |
} catch (UnsupportedEncodingException e) { | |
throw new IllegalStateException(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment