Pages

Tuesday, September 1, 2009

Encrypt URL

We have a major problem while calling some hyperlinks which will carry sensitive data, to avoid showing the parameters data while calling hyperlinks we have one beautiful concept in java is encryption we can do the encryption of total data and can decrypt the data while using.
But how to write the encryption code and decryption code, dont worry we no need to write the long lines code, we can use open source code for encryption and decryption given by Query Crypt.

Just follow the sample to encrypt the data.


                        <%@ page import="com.guhesan.querycrypt.QueryCrypt" %>
<%
String plainString = "BankID=1234&AccountID=J5678&TrasactionID=25";
String encryptedS = QueryCrypt.getInstance().encrypt(request, plainString);
%>
A HREF="<%=request.getContextPath()%>/URL_U_WANT_TO_GO.jsp?<%=encryptedS%>">Click here for the secure transaction /A
To do the decryption just go through the below code.

Suppose you had a encrypted string such as the following:
someURL.jsp?_tq=c95a29f62075cf63028be5ec6ba48be0
To decrypt in JSP:
  <%@ page import="com.guhesan.querycrypt.QueryCrypt" %>
<%@ page import="com.guhesan.querycrypt.beans.RequestParameterObject" %>
<%
RequestParameterObject rpo = QueryCrypt.getInstance().decrypt(request);
%>
You can now use the methods available in the RequestParameterObject to get the name value pairs.
The following methods are available for RequestParameterObject:
    java.util.Map RequestParameterObject.getParameterMap();
java.lang.String RequestParameterObject.getParameter(java.lang.String name);
java.util.Enumeration RequestParameterObject.getParameterNames();
java.lang.String[] RequestParameterObject.getParameterValues(java.lang.String name);
String RequestParameterObject.toString();


Source URL: http://www.avedatech.com/Products/QueryCrypt/index.jsp
you can download source files, jar files related to query crypt.

No comments:

Post a Comment