警告: 与第三方共享您的 TOTP 种子会破坏 TOTP 的多因素身份验证的基本假设 种子是秘密。
我生成了一个秘密
EBWFBWYCPPELHQS5
,我可以将其手动添加到 Google 身份验证器应用程序中。
但是,如果我通过谷歌图表 API 从这个秘密生成 QR 码,我无法扫描 QR 码,应用程序告诉我 QR 码无效。 这将是上面秘密的二维码:
我生成网址的代码如下所示:
public static String getQRBarcodeURL(String user, String host, String secret) {
return "https://chart.googleapis.com/chart?" + getQRBarcodeURLQuery(user, host, secret);
}
public static String getQRBarcodeURLQuery(String user, String host, String secret) {
return "chs=200x200&chld=M%7C0&cht=qr&chl=" +
getQRBarcodeOtpAuthURL(user, host, secret);
}
public static String getQRBarcodeOtpAuthURL(String user, String host, String secret) {
return String.format("otpauth://totp/%s@%s&secret=%s", user, host, secret);
}
我怎样才能让它工作
您需要对发送到 Google Charts API 的数据进行 URL 编码。
&
字符应该是
%26
,如下所示:
https://chart.googleapis.com/chart?chs=200x200&chld=M%7C0&cht=qr&chl=otpauth://totp/test@test%26secret=EBWFBWYCPPELHQS5
否则,API 会认为&
之后的所有内容都是它的另一个参数,而不是要编码的数据。