Results 1 to 5 of 5
- 03-11-2009, 04:53 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 4
- Rep Power
- 0
reading input from array and saving output to database md5 algorithm
I'm working on a project, and I need to run MD5 algorithm to generate a hex code. for that purpose i need to take different input everytime, my md5 algorithm is below....
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Test
{
public static void main(String[] args)
{
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();
System.out.println(""+ md5val);
}
}
}
1) the input should be random, it should be not taken from console.. we need to use some array or Random() class for taking input.
2) the output should be stored in the database... suppose in a field called password.
can u please help me...
thanking you...
- 03-12-2009, 05:53 AM #2
what data base are you using?
....
if its mysql try reading this:
Java Tips - How to connect MySql Server using JDBC
and you said that it should be a random number try using math.random
java tip Math.random
It's easy to write a code that computers can understand...
... the challenge is to write a code that humans can understand
- 03-12-2009, 05:55 AM #3
hmm.. the links are broken..
- 03-12-2009, 11:12 AM #4
Member
- Join Date
- Mar 2009
- Posts
- 4
- Rep Power
- 0
I am using ORACLE DB... 10g
- 03-12-2009, 11:25 AM #5
Member
- Join Date
- Mar 2009
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Saving and Reading files on hard drive from an applet
By DenniGa in forum Java AppletsReplies: 0Last Post: 02-26-2009, 03:13 AM -
Reading input file into an array
By littlefire in forum New To JavaReplies: 6Last Post: 10-18-2008, 11:51 PM -
how to record multiple input names and output later in program
By jbajwa1 in forum New To JavaReplies: 4Last Post: 10-02-2008, 10:05 PM -
saving date and time in a derby database from an ejb module
By Dave in forum Enterprise JavaBeans (EJB)Replies: 2Last Post: 07-22-2008, 11:14 AM -
Runtime.exec(), handling input and output streams
By crookshank in forum New To JavaReplies: 0Last Post: 06-05-2008, 02:41 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks