public static String decode64(String secret, String cipherAlgorithm, SecretKey cipherKey, PBEParameterSpec cipherSpec) throws GeneralSecurityException, UnsupportedEncodingException { byte[] encoding = Base64.decode(secret); byte[] decode = decode(encoding, cipherAlgorithm, cipherKey, cipherSpec); return new String(decode, "UTF-8"); }
public static String encode64(byte[] secret, String cipherAlgorithm, SecretKey cipherKey, PBEParameterSpec cipherSpec) throws Exception { byte[] encoding = encode(secret, cipherAlgorithm, cipherKey, cipherSpec); String b64 = Base64.encodeBytes(encoding); return b64; }
public static void main(String[] args) throws Exception { if (args.length != 3) { System.err.println("Encrypt a password" + "Usage: PBEUtils salt count domain-password password" + " salt : the Salt " + " count : the IterationCount " + " password : the plaintext password that should be encrypted"); throw new RuntimeException(" ERROR: please see format above"); } byte[] salt = args[0].substring(0, 8).getBytes(); int count = Integer.parseInt(args[1]); char[] password = "somearbitrarycrazystringthatdoesnotmatter".toCharArray(); byte[] passwordToEncode = args[2].getBytes("UTF-8"); PBEParameterSpec cipherSpec = new PBEParameterSpec(salt, count); PBEKeySpec keySpec = new PBEKeySpec(password); SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEwithMD5andDES"); SecretKey cipherKey = factory.generateSecret(keySpec); String encodedPassword = encode64(passwordToEncode, "PBEwithMD5andDES", cipherKey, cipherSpec); System.err.println("Encoded password: MASK-" + encodedPassword); } }
/** * 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 = PicketLinkCommonConstants.PBE_ALGORITHM; if (maskedString.startsWith(PicketLinkCommonConstants.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(PicketLinkCommonConstants.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 = PicketLinkCommonConstants.PBE_ALGORITHM; if (maskedString.startsWith(PicketLinkCommonConstants.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(PicketLinkCommonConstants.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 = PicketLinkCommonConstants.PBE_ALGORITHM; if (maskedString.startsWith(PicketLinkCommonConstants.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(PicketLinkCommonConstants.PASS_MASK_PREFIX.length()); String decodedValue = PBEUtils.decode64(maskedString, pbeAlgo, cipherKey, cipherSpec); maskedString = decodedValue; } return maskedString; }
public static String encode64(byte[] secret, String cipherAlgorithm, SecretKey cipherKey, PBEParameterSpec cipherSpec) throws Exception { byte[] encoding = encode(secret, cipherAlgorithm, cipherKey, cipherSpec); String b64 = Base64.encodeBytes(encoding); return b64; }
public static String decode64(String secret, String cipherAlgorithm, SecretKey cipherKey, PBEParameterSpec cipherSpec) throws GeneralSecurityException, UnsupportedEncodingException { byte[] encoding = Base64.decode(secret); byte[] decode = decode(encoding, cipherAlgorithm, cipherKey, cipherSpec); return new String(decode, "UTF-8"); }
public static void main(String[] args) throws Exception { if (args.length != 3) { System.err.println("Encrypt a password" + "Usage: PBEUtils salt count domain-password password" + " salt : the Salt " + " count : the IterationCount " + " password : the plaintext password that should be encrypted"); throw new RuntimeException(" ERROR: please see format above"); } byte[] salt = args[0].substring(0, 8).getBytes(); int count = Integer.parseInt(args[1]); char[] password = "somearbitrarycrazystringthatdoesnotmatter".toCharArray(); byte[] passwordToEncode = args[2].getBytes("UTF-8"); PBEParameterSpec cipherSpec = new PBEParameterSpec(salt, count); PBEKeySpec keySpec = new PBEKeySpec(password); SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEwithMD5andDES"); SecretKey cipherKey = factory.generateSecret(keySpec); String encodedPassword = encode64(passwordToEncode, "PBEwithMD5andDES", cipherKey, cipherSpec); System.err.println("Encoded password: MASK-" + encodedPassword); } }
String decodedValue; try { decodedValue = PBEUtils.decode64(val, pbeAlgo, cipherKey, cipherSpec); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e);
public static String encode64(byte[] secret, String cipherAlgorithm, SecretKey cipherKey, PBEParameterSpec cipherSpec) throws Exception { byte[] encoding = encode(secret, cipherAlgorithm, cipherKey, cipherSpec); String b64 = Base64.encodeBytes(encoding); return b64; }
public static String decode64(String secret, String cipherAlgorithm, SecretKey cipherKey, PBEParameterSpec cipherSpec) throws GeneralSecurityException, UnsupportedEncodingException { byte[] encoding = Base64.decode(secret); byte[] decode = decode(encoding, cipherAlgorithm, cipherKey, cipherSpec); return new String(decode, "UTF-8"); }
public static void main(String[] args) throws Exception { if (args.length != 3) { System.err.println("Encrypt a password" + "Usage: PBEUtils salt count domain-password password" + " salt : the Salt " + " count : the IterationCount " + " password : the plaintext password that should be encrypted"); throw new RuntimeException(" ERROR: please see format above"); } byte[] salt = args[0].substring(0, 8).getBytes(); int count = Integer.parseInt(args[1]); char[] password = "somearbitrarycrazystringthatdoesnotmatter".toCharArray(); byte[] passwordToEncode = args[2].getBytes("UTF-8"); PBEParameterSpec cipherSpec = new PBEParameterSpec(salt, count); PBEKeySpec keySpec = new PBEKeySpec(password); SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEwithMD5andDES"); SecretKey cipherKey = factory.generateSecret(keySpec); String encodedPassword = encode64(passwordToEncode, "PBEwithMD5andDES", cipherKey, cipherSpec); System.err.println("Encoded password: MASK-" + encodedPassword); } }
String decodedValue; try { decodedValue = PBEUtils.decode64(val, pbeAlgo, cipherKey, cipherSpec); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e);