@Test(priority = 8) public void testDecryptByPatternAndWrap() { String input = "{custom_crypt: EncryptMe}"; String customWrapper = "{custom_crypt:%s}"; Pattern customPattern = Pattern.compile("\\{custom_crypt:[^\\{\\}]*\\}"); String encrypted = cryptoTool.encryptByPatternAndWrap(input, customPattern, customWrapper); String decrypted = cryptoTool.decryptByPatternAndWrap(encrypted, customPattern, customWrapper); Assert.assertNotNull(decrypted); Assert.assertEquals(input, decrypted); }
public String decryptByPatternAndWrap(String content, Pattern pattern, String wrapper) { String wildcard = pattern.pattern().substring(pattern.pattern().indexOf("{") + 1, pattern.pattern().indexOf(":")); if (content != null && content.contains(wildcard)) { Matcher matcher = pattern.matcher(content); while (matcher.find()) { String group = matcher.group(); String crypt = StringUtils.removeStart(group, "{" + wildcard + ":").replace("}", ""); content = StringUtils.replace(content, group, String.format(wrapper, decrypt(crypt))); } } return content; }
CryptoTool { public String decryptByPatternAndWrap(String content, Pattern pattern, String wrapper) { String wildcard = pattern.pattern().substring(pattern.pattern().indexOf("{") + 1, pattern.pattern().indexOf(":")); if (content != null && content.contains(wildcard)) { Matcher matcher = pattern.matcher(content); while (matcher.find()) { String group = matcher.group(); String crypt = StringUtils.removeStart(group, "{" + wildcard + ":").replace("}", ""); content = StringUtils.replace(content, group, String.format(wrapper, decrypt(crypt))); } } return content; } }
CryptoTool { public String decryptByPatternAndWrap(String content, Pattern pattern, String wrapper) { String wildcard = pattern.pattern().substring(pattern.pattern().indexOf("{") + 1, pattern.pattern().indexOf(":")); if (content != null && content.contains(wildcard)) { Matcher matcher = pattern.matcher(content); while (matcher.find()) { String group = matcher.group(); String crypt = StringUtils.removeStart(group, "{" + wildcard + ":").replace("}", ""); content = StringUtils.replace(content, group, String.format(wrapper, decrypt(crypt))); } } return content; } CryptoTool(String cryptoAlgorithm, String cryptoKeyType, Key key);  CryptoTool();  CryptoTool(String cryptoKeyPath);  CryptoTool(String cryptoAlgorithm, String cryptoKeyType, String cryptoKeyPath); }
CryptoTool { public String decryptByPatternAndWrap(String content, Pattern pattern, String wrapper) { String wildcard = pattern.pattern().substring(pattern.pattern().indexOf("{") + 1, pattern.pattern().indexOf(":")); if (content != null && content.contains(wildcard)) { Matcher matcher = pattern.matcher(content); while (matcher.find()) { String group = matcher.group(); String crypt = StringUtils.removeStart(group, "{" + wildcard + ":").replace("}", ""); content = StringUtils.replace(content, group, String.format(wrapper, decrypt(crypt))); } } return content; } CryptoTool(String cryptoAlgorithm, String cryptoKeyType, Key key);  CryptoTool();  CryptoTool(String cryptoKeyPath);  CryptoTool(String cryptoAlgorithm, String cryptoKeyType, String cryptoKeyPath); String encrypt(String strToEncrypt); String decrypt(String strToDecrypt); String encryptByPattern(String content, Pattern pattern); String decryptByPattern(String content, Pattern pattern); String encryptByPatternAndWrap(String content, Pattern pattern, String wrapper); String decryptByPatternAndWrap(String content, Pattern pattern, String wrapper); String getAlgorithm(); void setAlgorithm(String algorithm); Cipher getCipher(); void setCipher(Cipher cipher); }
CryptoTool { public String decryptByPatternAndWrap(String content, Pattern pattern, String wrapper) { String wildcard = pattern.pattern().substring(pattern.pattern().indexOf("{") + 1, pattern.pattern().indexOf(":")); if (content != null && content.contains(wildcard)) { Matcher matcher = pattern.matcher(content); while (matcher.find()) { String group = matcher.group(); String crypt = StringUtils.removeStart(group, "{" + wildcard + ":").replace("}", ""); content = StringUtils.replace(content, group, String.format(wrapper, decrypt(crypt))); } } return content; } CryptoTool(String cryptoAlgorithm, String cryptoKeyType, Key key);  CryptoTool();  CryptoTool(String cryptoKeyPath);  CryptoTool(String cryptoAlgorithm, String cryptoKeyType, String cryptoKeyPath); String encrypt(String strToEncrypt); String decrypt(String strToDecrypt); String encryptByPattern(String content, Pattern pattern); String decryptByPattern(String content, Pattern pattern); String encryptByPatternAndWrap(String content, Pattern pattern, String wrapper); String decryptByPatternAndWrap(String content, Pattern pattern, String wrapper); String getAlgorithm(); void setAlgorithm(String algorithm); Cipher getCipher(); void setCipher(Cipher cipher);  }