Problem with the import java.security.*;

393 views
Skip to first unread message

Phani

unread,
Nov 28, 2008, 6:08:28 AM11/28/08
to Google Web Toolkit
Hi All,

In my application i have to implement a unique number generation i.e
UUID using SecureRandom class of java.security package. Please refer
the below code.
try {
// Create a secure random number generator
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
// Get 1024 random bits
byte[] bytes = new byte[1024/8];
sr.nextBytes(bytes);

// Create two secure number generators with the same seed
int seedByteCount = 10;
byte[] seed = sr.generateSeed(seedByteCount);
sr = SecureRandom.getInstance("SHA1PRNG");
sr.setSeed(seed);
SecureRandom sr2 = SecureRandom.getInstance("SHA1PRNG");
sr2.setSeed(seed);
} catch (NoSuchAlgorithmException e) {
}
But i'm facing a problem stating that java.security cannot be resolved
to a type. Please help me.Whether GWT doesn't support java.security
package?
Thanks in Advance,
Phani.

Peter Ondruška

unread,
Nov 28, 2008, 1:59:18 PM11/28/08
to Google-We...@googlegroups.com
I do not think you can do that with GWT. Therefore I use
http://uuid-service.appspot.com though not with GWT application.
Peter

2008/11/28, Phani <kphan...@gmail.com>:

medgey

unread,
Nov 29, 2008, 6:35:32 PM11/29/08
to Google Web Toolkit
If you are trying to use the java.security package on the client it is
unlikely that GWT supports them.

Sumit Chandel

unread,
Dec 1, 2008, 6:27:51 PM12/1/08
to Google-We...@googlegroups.com
Hi Phani,

I can confirm that the java.security package is not supported in GWT.

Keep in mind that GWT is for Ajax application development on the client-side, so all code gets cross-compiled from Java to obfuscated and optimized JavaScript that can run in the browser. Therefore, you are bound by the same browser limitations as any other Ajax framework, hence java.security functionality not being available on the client.

What you could do to solve the unique number generation problem in the code snippet above is have it run on the server and pass back the number to the client through a GWT RPC call or a RequestBuilder callback.

For more information on either technique, check out the GWT docs linked below.

GWT Developer Guide:

Hope that helps,
-Sumit Chandel
Reply all
Reply to author
Forward
0 new messages