@Test(priority = 8) public void testDecryptByPattern() { String input = "{crypt:EncryptMe}"; String resultInput = "EncryptMe"; String encrypted = cryptoTool.encryptByPattern(input, CRYPTO_PATTERN); String encryptedWithPattern = String.format("{crypt:%s}", encrypted); String decrypted = cryptoTool.decryptByPattern(encryptedWithPattern, CRYPTO_PATTERN); Assert.assertNotNull(decrypted); Assert.assertEquals(resultInput, decrypted); }
public String decryptByPattern(String content, Pattern pattern) { 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, decrypt(crypt)); } } if (content == null) { content = ""; } return content; }
CryptoTool { public String decryptByPattern(String content, Pattern pattern) { 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, decrypt(crypt)); } } if (content == null) { content = ""; } return content; } }
CryptoTool { public String decryptByPattern(String content, Pattern pattern) { 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, decrypt(crypt)); } } if (content == null) { content = ""; } return content; } CryptoTool(String cryptoAlgorithm, String cryptoKeyType, Key key);  CryptoTool();  CryptoTool(String cryptoKeyPath);  CryptoTool(String cryptoAlgorithm, String cryptoKeyType, String cryptoKeyPath); }
CryptoTool { public String decryptByPattern(String content, Pattern pattern) { 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, decrypt(crypt)); } } if (content == null) { content = ""; } 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 decryptByPattern(String content, Pattern pattern) { 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, decrypt(crypt)); } } if (content == null) { content = ""; } 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);  }