private String encrypt(String algorithm, String clearText) { Cipher cipher = ciphers.get(algorithm); if (cipher == null) { throw new IllegalArgumentException("Unknown cipher algorithm: " + algorithm); } return String.format("{%s}%s", algorithm, cipher.encrypt(clearText)); } }
public String decrypt(String encryptedText) { Matcher matcher = ENCRYPTED_PATTERN.matcher(encryptedText); if (matcher.matches()) { Cipher cipher = ciphers.get(matcher.group(1).toLowerCase(Locale.ENGLISH)); if (cipher != null) { return cipher.decrypt(matcher.group(2)); } } return encryptedText; }
private String encrypt(String algorithm, String clearText) { Cipher cipher = ciphers.get(algorithm); if (cipher == null) { throw new IllegalArgumentException("Unknown cipher algorithm: " + algorithm); } return String.format("{%s}%s", algorithm, cipher.encrypt(clearText)); } }
public String decrypt(String encryptedText) { Matcher matcher = ENCRYPTED_PATTERN.matcher(encryptedText); if (matcher.matches()) { Cipher cipher = ciphers.get(matcher.group(1).toLowerCase(Locale.ENGLISH)); if (cipher != null) { return cipher.decrypt(matcher.group(2)); } } return encryptedText; }
private String encrypt(String algorithm, String clearText) { Cipher cipher = ciphers.get(algorithm); if (cipher == null) { throw new IllegalArgumentException("Unknown cipher algorithm: " + algorithm); } return String.format("{%s}%s", algorithm, cipher.encrypt(clearText)); } }
public String decrypt(String encryptedText) { Matcher matcher = ENCRYPTED_PATTERN.matcher(encryptedText); if (matcher.matches()) { Cipher cipher = ciphers.get(matcher.group(1).toLowerCase(Locale.ENGLISH)); if (cipher != null) { return cipher.decrypt(matcher.group(2)); } } return encryptedText; }
ClassLoader cipherLoader = new URLClassLoader(new URL[]{new URL("jar:file:myAdditional.jar")}, Cipher.class.getClassLoader()); ServiceLoader<Cipher> serviceLoader = ServiceLoader.load(Cipher.class, cipherLoader); for(Cipher c : serviceLoader) { c.encrypt(...); }