, Google Authenticator , , , .
: Google Authenticator , base32 . , QR-, , base32, Google Authenticator.
EnterKeyActivity:
private boolean validateKeyAndUpdateStatus(boolean submitting) {
}
Google Authenticator , , . , , base32 .
EnterKeyActivity:
private String getEnteredKey() {
String enteredKey = mKeyEntryField.getText().toString();
return enteredKey.replace('1', 'I').replace('0', 'O');
}
protected void onRightButtonPressed() {
if (validateKeyAndUpdateStatus(true)) {
AuthenticatorActivity.saveSecret(this, mAccountName.getText().toString(), getEnteredKey(), null, mode, AccountDb.DEFAULT_HOTP_COUNTER);
exitWizard();
}
}
AuthenticatorActivity:
static boolean saveSecret(Context context, String user, String secret, String originalUser, OtpType type, Integer counter) {
if (secret != null) {
AccountDb accountDb = DependencyInjector.getAccountDb();
accountDb.update(user, secret, originalUser, type, counter);
}
}
Google Authenticator , base32, .
OtpProvider:
private String computePin(String secret, long otp_state, byte[] challenge) throws OtpSourceException {
try {
Signer signer = AccountDb.getSigningOracle(secret);
}
}
AccountDb:
static Signer getSigningOracle(String secret) {
try {
byte[] keyBytes = decodeKey(secret);
}
}
private static byte[] decodeKey(String secret) throws DecodingException {
return Base32String.decode(secret);
}
, base32 TOTP, , Google Authenticator . , , , , . , .
TL; DR
, /, Google Authenticator, base32. , base32, . Python / :
import base64
base64.b32encode(self.key)
base64.b32decode(self.key)