1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.web.format;
17
18 import java.security.GeneralSecurityException;
19
20 import org.kuali.rice.kns.service.KNSServiceLocator;
21
22
23
24
25
26
27 public class EncryptionFormatter extends Formatter {
28 private static final long serialVersionUID = -4109390572922205211L;
29
30 protected Object convertToObject(String target) {
31 if (Formatter.isEmptyValue(target))
32 return null;
33
34 String decryptedValue = null;
35 try {
36 decryptedValue = KNSServiceLocator.getEncryptionService().decrypt(target);
37 }
38 catch (GeneralSecurityException e) {
39 throw new RuntimeException("Unable to decrypt value.");
40 }
41
42 return decryptedValue;
43 }
44
45 public Object format(Object target) {
46 String encryptedValue = null;
47 try {
48 encryptedValue = KNSServiceLocator.getEncryptionService().encrypt(target);
49 }
50 catch (GeneralSecurityException e) {
51 throw new RuntimeException("Unable to encrypt secure field.");
52 }
53
54 return encryptedValue;
55 }
56 }