My current objective involves accessing a SecureRandom Java Object from Javascript. I aim to extract 4 bytes from the PRNG and convert it into a Javascript integer variable. The documentation states that the following two lines of Java code can be used to obtain 4 random bytes:
byte bytes[] = new byte[4];
random.nextBytes(bytes);
The main hurdles I'm facing are: 1) Allocating a byte array suitable for passing to a Java method 2) Parsing that array into an integer afterwards
Currently, I have managed to use the getSeed() method which returns an array of random bytes. When I view the rendered HTML code in Firefox, it displays "[B@16f70a4", which seems to be some form of pointer.
<script>
var sprng = new java.security.SecureRandom();
random = sprng.getSeed(4);
document.write(random + "<br/>\n");
</script>
This situation leads me to believe that I have successfully instantiated and accessed the Java class but encounter difficulties with type conversion.
I am seeking assistance in creating functions allocateJavaByteArray(N) and convertJavaByteArrayToInt(N) to enable the following code to function smoothly:
var sprng = new java.security.SecureRandom();
var nextBytes = allocateJavaByteArray(4);
srng.nextBytes(nextBytes);
var nextInt = convertJavaByteArrayToInt(4);
Your help is greatly appreciated.