Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass byte arrays between Java and JavaScript
    primarykey
    data
    text
    <p>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 <a href="http://download.oracle.com/javase/1.4.2/docs/api/java/security/SecureRandom.html" rel="noreferrer">http://download.oracle.com/javase/1.4.2/docs/api/java/security/SecureRandom.html</a>, the following two lines of Java code are supposed to do grab 4 random bytes:</p> <pre><code>byte bytes[] = new byte[4]; random.nextBytes(bytes); </code></pre> <p>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</p> <p>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.</p> <pre><code>&lt;script&gt; var sprng = new java.security.SecureRandom(); random = sprng.getSeed(4); document.write(random + "&lt;br/&gt;\n"); &lt;/script&gt; </code></pre> <p>This makes me think that I succeed to instantiate and access Java class, but have a problem with type conversion.</p> <p>Can anyone please help me to write <strong>allocateJavaByteArray(N)</strong> and <strong>convertJavaByteArrayToInt(N)</strong> to let the following code work:</p> <pre><code>var sprng = new java.security.SecureRandom(); var nextBytes = allocateJavaByteArray(4); srng.nextBytes(nextBytes); var nextInt = convertJavaByteArrayToInt(4); </code></pre> <p>Thank you in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload