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 | |
import java.io.OutputStream; |
20 | |
|
21 | |
import org.apache.commons.io.IOUtils; |
22 | |
|
23 | 0 | public abstract class AbstractNamedEncryptionStrategy implements EncryptionStrategy |
24 | |
{ |
25 | |
|
26 | |
private String name; |
27 | |
|
28 | |
public String getName() |
29 | |
{ |
30 | 0 | return name; |
31 | |
} |
32 | |
|
33 | |
public void setName(String name) |
34 | |
{ |
35 | 0 | this.name = name; |
36 | 0 | } |
37 | |
|
38 | |
public byte[] encrypt(byte[] data, Object info) throws CryptoFailureException { |
39 | 0 | InputStream io = this.encrypt(new ByteArrayInputStream(data), info); |
40 | |
try |
41 | |
{ |
42 | 0 | return IOUtils.toByteArray(io); |
43 | |
} |
44 | 0 | catch (IOException e) |
45 | |
{ |
46 | 0 | throw new CryptoFailureException(this, e); |
47 | |
} |
48 | |
} |
49 | |
|
50 | |
public byte[] decrypt(byte[] data, Object info) throws CryptoFailureException { |
51 | 0 | InputStream io = this.decrypt(new ByteArrayInputStream(data), info); |
52 | |
try |
53 | |
{ |
54 | 0 | return IOUtils.toByteArray(io); |
55 | |
} |
56 | 0 | catch (IOException e) |
57 | |
{ |
58 | 0 | throw new CryptoFailureException(this, e); |
59 | |
} |
60 | |
} |
61 | |
} |