View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
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  public abstract class AbstractNamedEncryptionStrategy implements EncryptionStrategy
20  {
21  
22      private String name;
23  
24      public String getName()
25      {
26          return name;
27      }
28  
29      public void setName(String name)
30      {
31          this.name = name;
32      }
33      
34      public byte[] encrypt(byte[] data, Object info) throws CryptoFailureException {
35          InputStream io = this.encrypt(new ByteArrayInputStream(data), info);
36          try
37          {
38              return IOUtils.toByteArray(io);
39          }
40          catch (IOException e)
41          {
42              throw new CryptoFailureException(this, e);
43          }
44      }
45  
46      public byte[] decrypt(byte[] data, Object info) throws CryptoFailureException {
47          InputStream io = this.decrypt(new ByteArrayInputStream(data), info);
48          try
49          {
50              return IOUtils.toByteArray(io);
51          }
52          catch (IOException e)
53          {
54              throw new CryptoFailureException(this, e);
55          }
56      }
57  }