Source:
<code>public String generateTOTPTokenLocal(String username) throws TOTPException { long token = 0; try { int tenantId = IdentityUtil.getTenantIdOFUser(username); UserRealm userRealm = TOTPManagerComponent.getRealmService().getTenantUserRealm(tenantId); if (userRealm != null) { UserStoreManager userStoreManager = userRealm.getUserStoreManager(); String secretKey = userStoreManager.getUserClaimValue(MultitenantUtils.getTenantAwareUsername (username), Constants.SECRET_KEY, null); byte[] secretkey; <START> String encoding = "Base32"; <END> try { encoding = TOTPUtil.getEncodingMethod(); } catch (IdentityApplicationManagementException e) { log.error("Error when fetching the encoding method"); } if ("Base32".equals(encoding)) { Base32 codec32 = new Base32(); secretkey = codec32.decode(secretKey); } else { Base64 code64 = new Base64(); secretkey = code64.decode(secretKey); } try { token = getCode(secretkey, getTimeIndex()); sendNotification("TOTP token Generator",username,Long.toString(token)); if (log.isDebugEnabled()) { log.debug("Token is sent to via email to the user : " + username); } } catch (NoSuchAlgorithmException e) { throw new TOTPException("TOTPTokenGenerator can't find the configured hashing algorithm", e); } catch (InvalidKeyException e) { throw new TOTPException("Secret key is not valid", e); } } else { throw new TOTPException("Cannot find the user realm for the given tenant domain : " + CarbonContext .getThreadLocalCarbonContext().getTenantDomain()); } } catch (IdentityException e) { throw new TOTPException("TOTPTokenGenerator failed while trying to get the tenant ID of the user " + username, e); } catch (UserStoreException e) { throw new TOTPException("TOTPTokenGenerator failed while trying to access userRealm of the user : " + username, e); } return Long.toString(token); }</code><technical_language>defined Constants</technical_language>

Target:
public String generateTOTPTokenLocal(String username) throws TOTPException { long token = 0; try { int tenantId = IdentityUtil.getTenantIdOFUser(username); UserRealm userRealm = TOTPManagerComponent.getRealmService().getTenantUserRealm(tenantId); if (userRealm != null) { UserStoreManager userStoreManager = userRealm.getUserStoreManager(); String secretKey = userStoreManager.getUserClaimValue(MultitenantUtils.getTenantAwareUsername (username), Constants.SECRET_KEY_CLAIM_URL, null); byte[] secretkey; String encoding = Constants.BASE32; try { encoding = TOTPUtil.getEncodingMethod(); } catch (IdentityApplicationManagementException e) { log.error("Error when fetching the encoding method"); } if (Constants.BASE32.equals(encoding)) { Base32 codec32 = new Base32(); secretkey = codec32.decode(secretKey); } else { Base64 code64 = new Base64(); secretkey = code64.decode(secretKey); } try { token = getCode(secretkey, getTimeIndex()); sendNotification("TOTP token Generator",username,Long.toString(token)); if (log.isDebugEnabled()) { log.debug("Token is sent to via email to the user : " + username); } } catch (NoSuchAlgorithmException e) { throw new TOTPException("TOTPTokenGenerator can't find the configured hashing algorithm", e); } catch (InvalidKeyException e) { throw new TOTPException("Secret key is not valid", e); } } else { throw new TOTPException("Cannot find the user realm for the given tenant domain : " + CarbonContext .getThreadLocalCarbonContext().getTenantDomain()); } } catch (IdentityException e) { throw new TOTPException("TOTPTokenGenerator failed while trying to get the tenant ID of the user " + username, e); } catch (UserStoreException e) { throw new TOTPException("TOTPTokenGenerator failed while trying to access userRealm of the user : " + username, e); } return Long.toString(token); }