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