如何在jsp中加密/编码url参数 [英] how to encrypt/encode url parameters in jsp

查看:510
本文介绍了如何在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'

这篇关于如何在jsp中加密/编码url参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆