I need to access SecureRandom Java Object from Javascript. My ultimate goal is to grab 4 bytes from PRNG and convert it to Javascript integer variable. According to http://download.oracle.com/javase/1.4.2/docs/api/java/security/SecureRandom.html, the following two lines of Java code are supposed to do grab 4 random bytes:
byte bytes[] = new byte[4];
random.nextBytes(bytes);
My problems is that I don't know how to 1) allocate byte array suitable for passing to Java method 2) parse that array into integer afterwards
So far I have managed to getSeed() method which returns an array of random bytes. When I render HTML code provided below in Firefox it shows "[B@16f70a4", which appears to be a pointer or something.
<script>
var sprng = new java.security.SecureRandom();
random = sprng.getSeed(4);
document.write(random + "<br/>\n");
</script>
This makes me think that I succeed to instantiate and access Java class, but have a problem with type conversion.
Can anyone please help me to write allocateJavaByteArray(N) and convertJavaByteArrayToInt(N) to let the following code work:
var sprng = new java.security.SecureRandom();
var nextBytes = allocateJavaByteArray(4);
srng.nextBytes(nextBytes);
var nextInt = convertJavaByteArrayToInt(4);
Thank you in advance.