Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8041441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:13:19+00:00 2026-06-05T04:13:19+00:00

On a tomcat, I have two webapplications i.e app1 and app2. I send URL

  • 0

On a tomcat, I have two webapplications i.e app1 and app2. I send URL from app1 in encrypted form (using below program) to app2 . I send the URL through response.sendRedirect(encryptedURL).Then at app2 I get this encrypted URL. I see there are some extra characters like +,space( ) in this encrypted URL at app2. I want the exact same URL at app2. I am not getting why these extra characters getting inserted?

Here is the URL at app1 after encryption

 Rc9mgB+18chPk6nk1+gzpws6dO5/TSkcOYy8rbuVVTmjE9YjLt5w0EMpuhh+QBKzReYO34pAquf9
 kmYOiwl99jo2kDCCkYHMh/+nxEgs1yrLYagsc/0p5KdYeMy1eWeUQB8KqmNlhtYysrHhOYVuunUi
 dTaEKUTSWd8lPg9/wZfHdBoJgaF40aUW3FeRODVL

Here is the value of this encrypted URL at app2 when I get it with req.getParameter(“encryptedURL”);

 Rc9mgB 18chPk6nk1 gzpws6dO5/TSkcOYy8rbuVVTmjE9YjLt5w0EMpuhh QBKzReYO34pAquf9  kmYOiwl99jo2kDCCkYHMh/ nxEgs1yrLYagsc/0p5KdYeMy1eWeUQB8KqmNlhtYysrHhOYVuunUi  dTaEKUTSWd8lPg9/wZfHdBoJgaF40aUW3FeRODVL

Here is the program for encryption

 import java.security.Key;
 import javax.crypto.Cipher;
 import javax.crypto.spec.SecretKeySpec;
 import sun.misc.BASE64Decoder;
 import sun.misc.BASE64Encoder;

 public class AESEncryptionDecryptionTest {

   private static final String ALGORITHM       = "AES";
   private static final String myEncryptionKey = "ThisIsFoundation";
   private static final String UNICODE_FORMAT  = "UTF8";

   public static String encrypt(String valueToEnc) throws Exception {
 Key key = generateKey();
 Cipher c = Cipher.getInstance(ALGORITHM);
 c.init(Cipher.ENCRYPT_MODE, key);  
 byte[] encValue = c.doFinal(valueToEnc.getBytes());
 String encryptedValue = new BASE64Encoder().encode(encValue);
 return encryptedValue;
   }


private static Key generateKey() throws Exception {
byte[] keyAsBytes;
keyAsBytes = myEncryptionKey.getBytes(UNICODE_FORMAT);
Key key = new SecretKeySpec(keyAsBytes, ALGORITHM);
return key;
}


}

EDIT:-Looks like very close to it. here is my new code and finding

This is the parameter I am encrypting at app1

 mySession=84088586B45317C3600978DF9F52A699&securityTok=44a2e4dd89ed1aad438d5e3c16ff528&myurl=https://10.205.112.83:8443

// encrypted as you suggested at app1 and sending encryptedParam as request parameter

//now getting the encryptedParam at app2 from request and decrypted as per your suggestion . As you can see below
everything is decrypted fine at app2 except my URL part(i.e =https://10.205 replaced with ½‡è˜�Àg¸l½.µbO’)

mySession=84088586B45317C3600978DF9F52A699&securityTok=44a2e4dd89ed1aad438d5e3c16ff528&myurl½‡è˜�Àg¸l½.µbO’112.83:8443

Code is

   public static String encrypt(String valueToEnc) throws Exception {
    Key key = generateKey();
    // Key key = buildKey();
    Cipher c = Cipher.getInstance(ALGORITHM);
    c.init(Cipher.ENCRYPT_MODE, key);
    byte[] encValue = c.doFinal(valueToEnc.getBytes(UNICODE_FORMAT));
    String encryptedValue1 = new BASE64Encoder().encode(encValue);
    String encryptedValue = URLEncoder.encode(encryptedValue1);
    return encryptedValue;
  }

  public static String decrypt(String encryptedValue) throws Exception {
    Key key = generateKey();
    // Key key = buildKey();
    Cipher c = Cipher.getInstance(ALGORITHM);
    c.init(Cipher.DECRYPT_MODE, key);
    String decordedValueStr = URLDecoder.decode(encryptedValue);
    byte[] decordedValue = new BASE64Decoder().decodeBuffer(decordedValueStr);
    byte[] decValue = c.doFinal(decordedValue);
    // String try1=new BASE64Encoder().encode(decValue);
    String decryptedValue = new String(decValue);
    return decryptedValue;
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:13:21+00:00Added an answer on June 5, 2026 at 4:13 am

    In your encrypt method instead of:

    return encryptedValue;
    

    use this code:

    return URLEncoder.encode(encryptedValue);
    

    then on receiving side call URLDecoder#decode:

    String tmpUrl = URLDecoder.decode(encryptedURL);
    // call BASE64Decoder on tmpUrl
    // call decrypt on return value of BASE64Decoder
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using tomcat, I have two web-applications i.e app1 and app2. I sent url from
I have two applications under tomcat/webapps folder. tomcat/webapps/App1 tomcat/webapps/App2 Both applications share the same
i have two https web applications app1 and app2 installed on two different tomcats
hi i am using tomcat 6 as webserver. i have two webbapplication installed on
I have two queries which I am detailing below: I installed tomcat 7.0 on
I am using Tomcat version 5.5 and have two questions. I am starting tomcat
I am using Tomcat 7 as a servlet container and I have two war
I have two tomcat web applications that need to share information using a singleton.
I am using tomcat 6 and I have two webapps. One is webapp1 and
I have two web applications that are running on a single Tomcat server and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.