1 package org.kuali.common.util.encrypt.jasypt;
2
3 import static org.kuali.common.util.encrypt.EncryptionStrength.DEFAULT_ENCRYPTION_STRENGTH;
4 import static org.kuali.common.util.encrypt.jasypt.Jasypt.buildTextEncryptor;
5
6 import org.jasypt.util.text.TextEncryptor;
7 import org.kuali.common.util.encrypt.EncryptionContext;
8 import org.kuali.common.util.encrypt.EncryptionStrength;
9 import org.kuali.common.util.encrypt.Encryptor;
10
11 public final class DefaultJasyptEncryptor implements Encryptor {
12
13 public DefaultJasyptEncryptor(String password) {
14 this(password, DEFAULT_ENCRYPTION_STRENGTH);
15 }
16
17 public DefaultJasyptEncryptor(String password, EncryptionStrength strength) {
18 this(new EncryptionContext(password, strength));
19 }
20
21 public DefaultJasyptEncryptor(EncryptionContext context) {
22 this.encryptor = buildTextEncryptor(context.getPassword(), context.getStrength());
23 }
24
25 private final TextEncryptor encryptor;
26
27 @Override
28 public String encrypt(String text) {
29 return encryptor.encrypt(text);
30 }
31
32 @Override
33 public String decrypt(String text) {
34 return encryptor.decrypt(text);
35 }
36
37 }