Window.crypto
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Window.crypto
propriedade somente de leitura, devolve um objeto do tipo Crypto
associado ao objeto global. Este objeto permite que páginas da web utilizem recursos de criptografia.
Sintaxe
var cryptoObj = window.crypto || window.msCrypto; // for IE 11
Exemplo
Usando a propriedade Window.crypto
para acessar o método getRandomValues()
JavaScript
js
genRandomNumbers = function getRandomNumbers() {
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] + " ";
}
};
HTML
html
<p id="myRandText">The random numbers are:</p>
<button type="button" onClick="genRandomNumbers()">
Generate 10 random numbers
</button>
Resultado
Especificações
Specification |
---|
Web Cryptography API # dom-windoworworkerglobalscope-crypto |
Compatibilidade com navegadores
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
crypto | ||||||||||||||
Available in workers |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Partial support
- Partial support
- Uses a non-standard name.
- Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Veja também
- O objeto global
Window