/** * Given a masked password {@link String}, decode it * * @param maskedString a password string that is masked * @param salt Salt * @param iterationCount Iteration Count * @return Decoded String * @throws Exception */ public static String decode(String maskedString, String salt, int iterationCount) throws Exception { String pbeAlgo = PicketLinkFederationConstants.PBE_ALGORITHM; if (maskedString.startsWith(PicketLinkFederationConstants.PASS_MASK_PREFIX)) { // Create the PBE secret key SecretKeyFactory factory = SecretKeyFactory.getInstance(pbeAlgo); char[] password = "somearbitrarycrazystringthatdoesnotmatter".toCharArray(); PBEParameterSpec cipherSpec = new PBEParameterSpec(salt.getBytes(), iterationCount); PBEKeySpec keySpec = new PBEKeySpec(password); SecretKey cipherKey = factory.generateSecret(keySpec); maskedString = maskedString.substring(PicketLinkFederationConstants.PASS_MASK_PREFIX.length()); String decodedValue = PBEUtils.decode64(maskedString, pbeAlgo, cipherKey, cipherSpec); maskedString = decodedValue; } return maskedString; } }
/** * Given a masked password {@link String}, decode it * @param maskedString a password string that is masked * @param salt Salt * @param iterationCount Iteration Count * @return Decoded String * @throws Exception */ public static String decode(String maskedString, String salt, int iterationCount) throws Exception { String pbeAlgo = PicketLinkFederationConstants.PBE_ALGORITHM; if (maskedString.startsWith(PicketLinkFederationConstants.PASS_MASK_PREFIX)) { // Create the PBE secret key SecretKeyFactory factory = SecretKeyFactory.getInstance(pbeAlgo); char[] password = "somearbitrarycrazystringthatdoesnotmatter".toCharArray(); PBEParameterSpec cipherSpec = new PBEParameterSpec(salt.getBytes(), iterationCount); PBEKeySpec keySpec = new PBEKeySpec(password); SecretKey cipherKey = factory.generateSecret(keySpec); maskedString = maskedString.substring(PicketLinkFederationConstants.PASS_MASK_PREFIX.length()); String decodedValue = PBEUtils.decode64(maskedString, pbeAlgo, cipherKey, cipherSpec); maskedString = decodedValue; } return maskedString; } }
/** * Given a masked password {@link String}, decode it * @param maskedString a password string that is masked * @param salt Salt * @param iterationCount Iteration Count * @return Decoded String * @throws Exception */ public static String decode(String maskedString, String salt, int iterationCount) throws Exception { String pbeAlgo = PicketLinkFederationConstants.PBE_ALGORITHM; if (maskedString.startsWith(PicketLinkFederationConstants.PASS_MASK_PREFIX)) { // Create the PBE secret key SecretKeyFactory factory = SecretKeyFactory.getInstance(pbeAlgo); char[] password = "somearbitrarycrazystringthatdoesnotmatter".toCharArray(); PBEParameterSpec cipherSpec = new PBEParameterSpec(salt.getBytes(), iterationCount); PBEKeySpec keySpec = new PBEKeySpec(password); SecretKey cipherKey = factory.generateSecret(keySpec); maskedString = maskedString.substring(PicketLinkFederationConstants.PASS_MASK_PREFIX.length()); String decodedValue = PBEUtils.decode64(maskedString, pbeAlgo, cipherKey, cipherSpec); maskedString = decodedValue; } return maskedString; } }
String decodedValue; try { decodedValue = PBEUtils.decode64(val, pbeAlgo, cipherKey, cipherSpec); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e);
try decodedValue = PBEUtils.decode64(val, pbeAlgo, cipherKey, cipherSpec);
try decodedValue = PBEUtils.decode64(val, pbeAlgo, cipherKey, cipherSpec);