Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-12-2009, 08:20 PM
Member
 
Join Date: Mar 2009
Posts: 4
Rep Power: 0
avinash4m is on a distinguished road
Default run MD5 algorithm in Java Servlet
Hey! please help me....


Acutally I need to implement the MD5 algorithm in servlets... I'm strucked at below positions

1. Reading an input to the algorithm

2. saving the output of the algorithm in to database table.... i.e., update the record..

import database.*;
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Test extends HttpServlet
{ Connection con;
Statement stmt;
PreparedStatement pstmt;
public void service(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException
{
String md5val = "12";
MessageDigest algorithm = null;

try
{
algorithm = MessageDigest.getInstance("MD5");
}
catch (NoSuchAlgorithmException nsae)
{
System.out.println("Cannot find digest algorithm");
System.exit(1);
}

for (String arg : args)
{
byte[] defaultBytes = arg.getBytes();
algorithm.reset();
algorithm.update(defaultBytes);
byte messageDigest[] = algorithm.digest();
StringBuffer hexString = new StringBuffer();

for (int i = 0; i < messageDigest.length; i++)
{
String hex = Integer.toHexString(0xFF & messageDigest[i]);
if (hex.length() == 1)
{
hexString.append('0');
}
hexString.append(hex);
}
md5val = hexString.toString();
resp.setContentType("text/html");
PrintWriter out=resp.getWriter();
try{
// Need to read input from md5val

con=DBConn.getConnection();
pstmt=DBConn.prepareStatement("insert into onetimepwd values(?)");
pstmt.setString(1,otpwd);// need to update into the database table

pstmt.execute();
pstmt.close();
out.println("<body bgcolor='#A3A3D1'><center><h1><B><I>Successfully Registered</I>" );
out.print("</B></h1></center></body>");
DBConn.close();
}
catch(Exception e)
{
System.out.println("in userreg");
e.printStackTrace();
System.out.println("in userreg");
}}
}
}


Thank you
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Algorithm problems? JavaInLove New To Java 8 07-02-2008 09:50 AM
Algorithm statement in my Java codes javanewbie New To Java 2 06-24-2008 03:52 PM
Soundex Algorithm Implementation in Java Java Tip java.lang 0 04-12-2008 09:40 PM
Using Java To Implement RSA Algorithm Floetic New To Java 3 04-01-2008 12:56 AM
Help with algorithm in java coco AWT / Swing 1 08-01-2007 07:45 AM


All times are GMT +2. The time now is 05:54 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org