title: How to encrypt URL request parameter values in java for use in an emailed link
body: <p>I am facing one problem related to encrypt url request parameter values.
  My scene is this I am sending one hyperlink to user through email and I want to hide url contains data from user.
  Url contains data that I am accessing through request object in struts application. and same values I am using on jsp page by using EL.
  So how can I encrypt data and how to maintain on jsp page and struts also?</p>
  
  <p>below code I am using for encrypt ans decrypt the data...
  but If i encrypt my request parameter value then how I can get decrypted value at jsp?</p>
  
  <pre><code>import java.security.Key;
  
  import javax.crypto.Cipher;
  import javax.crypto.spec.SecretKeySpec;
  
  import sun.misc.BASE64Decoder;
  import sun.misc.BASE64Encoder;
  
  @SuppressWarnings("restriction")
  public class EncryptDecrypt {
  
      private static final String ALGO = "AES";
      private static final byte[] keyValue = new byte[] { 'T', 'h', 'e', 'B',
              'e', 's', 't', 'S', 'e', 'c', 'r', 'e', 't', 'K', 'e', 'y' };
  
      public static String encrypt(String Data) throws Exception {
          Key key = generateKey();
          Cipher c = Cipher.getInstance(ALGO);
          c.init(Cipher.ENCRYPT_MODE, key);
          byte[] encVal = c.doFinal(Data.getBytes());
          String encryptedValue = new BASE64Encoder().encode(encVal);
          return encryptedValue;
      }
  
      public static String decrypt(String encryptedData) throws Exception {
          Key key = generateKey();
          Cipher c = Cipher.getInstance(ALGO);
          c.init(Cipher.DECRYPT_MODE, key);
          byte[] decordedValue = new BASE64Decoder().decodeBuffer(encryptedData);
          byte[] decValue = c.doFinal(decordedValue);
          String decryptedValue = new String(decValue);
          return decryptedValue;
      }
  
      private static Key generateKey() throws Exception {
          Key key = new SecretKeySpec(keyValue, ALGO);
          return key;
      }
  
  }
  </code></pre>