?
Solved

random message in java

Posted on 2003-02-19
5
Medium Priority
?
235 Views
Last Modified: 2010-03-31
hai,

     I want to post a challenge to the client to know whether the client has private key corresponding to the public key i have. for that,i have to generate a random message which should be encrypted using client's public key and post as a challenge to client.

     can i generate the random message using java.util.Random. I want to create a random string array.
please give some idea.

-selvi
0
Comment
Question by:tamilselvi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 9

Accepted Solution

by:
Venci75 earned 80 total points
ID: 7985895
Create a char array containing all allowed characters for the message. Then in a loop - generate random index (using java.util.Random) and append the corresponding character to the message
0
 

Expert Comment

by:davestubbs
ID: 7986730
There is no existing method to do that in the JDK, but this is the code I use to generate random passwords in our application.

import java.util.*;
/**
 * <CODE>RandomString</CODE> provides the ability to generate strings of random characters
 * to a predetermined size.
 * <p>
 */
public class RandomString
{
     // Base string of characters allowed to constitute the resulting random string.
     private static String characters= "123465789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

     // Number of characters in the base string used as the modifier for the random seed.
     private static int randomLength= characters.length();

     /**
      * Returns the randomised string of the length specified.
      *
      * @return           the string of random characters.
      * @param   length   the number of characters required in the random string.
      */
     public static String createRandomString(int length)
     {
          StringBuffer random = new StringBuffer(length + 1);

          for (int loop = 0 ; loop < length ; loop ++)
               random.append(characters.charAt(new Double(Math.random() * randomLength).intValue()));

          return random.toString();    
     }
}
0
 

Expert Comment

by:CleanupPing
ID: 9059217
tamilselvi:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 7

Expert Comment

by:tomboshell
ID: 9553171
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept Venci75's comment as answer.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Thomas Boshell
EE Cleanup Volunteer
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Usersā€™ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET ā€¦
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question