如何在jsp中加密/编码url参数

问题描述:

我想对URL变量进行加密,以便在jsp中传递信息时用户无法看到或修改信息.

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

这是一个示例网址:

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

在这里,我想对参数idtname进行加密或编码.

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


我正在以电子邮件附件的形式发送此网址...当收件人单击此链接时,其薪水单信息将显示在网页上


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'

最好的方法是在不使用任何第三方库的情况下在Base64中进行编码/解码,可以使用Using sun.misc.BASE64Encoder/sun.misc.BASE64Decoder.

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);

发送"encoded_id"作为网址参数,而不是传递"id"

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