by Anish
Posted on Sunday september 11, 2018
This sample chapter extracted from the book, Cryptography for JavaScript Developers.
The Window.crypto
read-only property returns the Crypto
object associated to the global object. This object allows web pages access to certain cryptographic related services.
Using the Window.crypto
property to access the getRandomValues() method.
<script>
genRandomNumbers = function getRandomNumbers() {
if (window.crypto || window.msCrypto)
{
var array = new Uint32Array(10);
window.crypto.getRandomValues(array);
var randText = document.getElementById("myRandText");
randText.innerHTML = "The random numbers are: "
for (var i = 0; i < array.length; i++) {
randText.innerHTML += array[i] + " \n";
}
}
else throw new Error("Your browser can't generate secure random numbers");
}
</script>
<p id="myRandText">The random numbers are: </p>
<button type="button" onClick='genRandomNumbers()'>Generate 10 random numbers</button>
The random numbers are:
The following browser has the support of window.crypto
Thanku for reading !!! Give a Share for Support
Asking for donation sound bad to me, so i'm raising fund from by offering all my Nine book for just $9