@Test(priority = 8) public void testEncryptByPattern() { String input = "{crypt: EncryptMe}"; String encrypted = cryptoTool.encryptByPattern(input, CRYPTO_PATTERN); Assert.assertNotNull(encrypted); Assert.assertFalse(encrypted.equals(input)); }
public String encryptByPattern(String content, Pattern pattern) { if (isEncrypted(content, 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, encrypt(crypt)); } } } return content; }
CryptoTool { public String encryptByPattern(String content, Pattern pattern) { if (isEncrypted(content, 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, encrypt(crypt)); } } } return content; } }
CryptoTool { public String encryptByPattern(String content, Pattern pattern) { if (isEncrypted(content, 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, encrypt(crypt)); } } } return content; } CryptoTool(String cryptoAlgorithm, String cryptoKeyType, Key key);  CryptoTool();  CryptoTool(String cryptoKeyPath);  CryptoTool(String cryptoAlgorithm, String cryptoKeyType, String cryptoKeyPath); }
CryptoTool { public String encryptByPattern(String content, Pattern pattern) { if (isEncrypted(content, 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, encrypt(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 encryptByPattern(String content, Pattern pattern) { if (isEncrypted(content, 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, encrypt(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);  }