Results 1 to 5 of 5
  1. #1
    avinash4m is offline Member
    Join Date
    Mar 2009
    Posts
    4
    Rep Power
    0

    Default 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...

  2. #2
    azzaiel's Avatar
    azzaiel is offline Member
    Join Date
    Feb 2009
    Posts
    57
    Rep Power
    0

    Default

    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

  3. #3
    critdevil's Avatar
    critdevil is offline Member
    Join Date
    Mar 2009
    Posts
    8
    Rep Power
    0

    Default

    hmm.. the links are broken..

  4. #4
    avinash4m is offline Member
    Join Date
    Mar 2009
    Posts
    4
    Rep Power
    0

    Default

    I am using ORACLE DB... 10g

  5. #5
    avinash4m is offline Member
    Join Date
    Mar 2009
    Posts
    4
    Rep Power
    0

Similar Threads

  1. Replies: 0
    Last Post: 02-26-2009, 04:13 AM
  2. Reading input file into an array
    By littlefire in forum New To Java
    Replies: 6
    Last Post: 10-19-2008, 12:51 AM
  3. Replies: 4
    Last Post: 10-02-2008, 11:05 PM
  4. saving date and time in a derby database from an ejb module
    By Dave in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 07-22-2008, 12:14 PM
  5. Runtime.exec(), handling input and output streams
    By crookshank in forum New To Java
    Replies: 0
    Last Post: 06-05-2008, 03:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •