[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

random message in java

Posted on 2003-02-19
5
Medium Priority
?
236 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
4 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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

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 how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

612 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