1
2
3
4
5
6
7
8
9
10
11 package org.mule.security;
12
13 import org.mule.api.EncryptionStrategy;
14 import org.mule.api.security.CryptoFailureException;
15
16 import java.io.ByteArrayInputStream;
17 import java.io.IOException;
18 import java.io.InputStream;
19
20 import org.apache.commons.io.IOUtils;
21
22 public abstract class AbstractNamedEncryptionStrategy implements EncryptionStrategy
23 {
24
25 private String name;
26
27 public String getName()
28 {
29 return name;
30 }
31
32 public void setName(String name)
33 {
34 this.name = name;
35 }
36
37 public byte[] encrypt(byte[] data, Object info) throws CryptoFailureException {
38 InputStream io = this.encrypt(new ByteArrayInputStream(data), info);
39 try
40 {
41 return IOUtils.toByteArray(io);
42 }
43 catch (IOException e)
44 {
45 throw new CryptoFailureException(this, e);
46 }
47 }
48
49 public byte[] decrypt(byte[] data, Object info) throws CryptoFailureException {
50 InputStream io = this.decrypt(new ByteArrayInputStream(data), info);
51 try
52 {
53 return IOUtils.toByteArray(io);
54 }
55 catch (IOException e)
56 {
57 throw new CryptoFailureException(this, e);
58 }
59 }
60 }