how to encrypt/encode url parameters in jsp

10,096

The best way to encode / decode in Base64 without using any third party libraries, you can use Using sun.misc.BASE64Encoder / sun.misc.BASE64Decoder.

try  this snippet 



  String id="1234";
  byte[]   bytesEncoded = Base64.encodeBase64(id.getBytes());//encoding part
  String encoded_id=new String(bytesEncoded);


  String id1=request.getParameter("id");
  byte[] valueDecoded= Base64.decodeBase64(id1);//decoding part
  String decoded_id=new String(valueDecoded);

Send 'encoded_id' as a url parameter instead of passing 'id'

Share:
10,096
Dileep Kumar
Author by

Dileep Kumar

Updated on June 05, 2022

Comments

  • Dileep Kumar
    Dileep Kumar almost 2 years

    I want to encrypt a URL variable so that the user can't see or modify the information when it is passed in jsp.

    This is an example URL:

    localhost/somewebpage/name.jsp?id=1234&tname=Employee_March_2013
    

    Here I want to encrypt or encode the parameters id and tname.

    Could someone please help me write a short script that encodes / encrypts and then decrypts the parameters

    EDIT:
    I am sending this url as a attachment in email... when receiver clicks on this link their payslip information will displayed on the web page'

  • GitaarLAB
    GitaarLAB almost 10 years
    You do realize this is about a link that is EMAILED to the user?