Math.random()的加密安全替换方法window.crypto.getRandomValues
Math.random()
window.crypto.getRandomValues
Crypto.getRandomValues() 方法让你可以获取符合密码学要求的安全的随机值。传入参数的数组被随机值填充(在加密意义上的随机)。
为了确保足够的性能,不使用真正的随机数生成器,但是它们正在使用具有足够熵值伪随机数生成器。它所使用的 PRNG 的实现与其他不同,但适用于加密的用途。该实现还需要使用具有足够熵的种子,如系统级熵源。
语法
cryptoObj.getRandomValues(typedArray);
参数
typedArray是一个基于整数的 TypedArray,它可以是 Int8Array、Uint8Array、Int16Array、 Uint16Array、 Int32Array 或者 Uint32Array。在数组中的所有的元素会被随机数重写。(注释:生成的随机数储存在 typedArray 数组上。)
例子
window.crypto.getRandomValues(new Int8Array(2))//Int8Array(2) [44, -3]
window.crypto.getRandomValues(new Uint8Array(2))//Uint8Array(2) [218, 119]
window.crypto.getRandomValues(new Int16Array(2))//Int16Array(2) [24582, -15808]
window.crypto.getRandomValues(new Uint16Array(2))//Uint16Array(2) [55391, 55756]
window.crypto.getRandomValues(new Int32Array(2))//Int32Array(2) [1574608122, -836595554]
window.crypto.getRandomValues(new Uint32Array(2))//Uint32Array(2) [1906545366, 2391348462]
Math.random()的等价表达式:window.crypto.getRandomValues(new Uint8Array(1)) * 0.001
详见:https://developer.mozilla.org/zh-CN/docs/Web/API/RandomSource/getRandomValues
Math.random()的加密安全替换方法window.crypto.getRandomValues的更多相关文章
- 通过window.crypto.getRandomValues获得一个大于零的随机数
window.crypto.getRandomValues(new Uint32Array(1))[0]; 浏览器支持情况如下: IE: no IE Mobile: no Firefox24+ Fir ...
- java中random的几个方法的使用Math.random()和random().
random java中我们有时候也需要使用使用random来产生随机数,下面我来简单的介绍下java中random的使用方法 第一种:Math.random() public static doub ...
- Random.nextInt()替换Math.random()
在项目中使用哪个随机数 文章参考 http://liukai.iteye.com/blog/433718 今天用了find bugs后查出来了个问题 Google了下 发现 Random.nextin ...
- Math.random 随机数方法
随机取数方法 Math.random() 表示0到1之间随机取一个数 <x< 小数 Math.random()* 表示0<x< parseInt(Math.random()*) ...
- Random类和Math.random()方法
一.Random类的定义Random类位于 java.util 包中,主要用于生成伪 随机数Random类将 种子数 作为随机算法的起源数字,计算生成伪随机数,其与生成的随机数字的区间无关创建Rand ...
- 生成随机数的几种方法、Math.random()随机数的生成、Random()的使用
第一种方法使用:System.currentTimeMillis(); final long l = System.currentTimeMillis(); final int rs = (int) ...
- javascript 中根据sort 方法随机数组 (Math.random)
var arr = [1,2,3,4,5,6,7,8,9,10]; function Arandom(a,b){ return (Math.random() > 0.5) ? 1 : -1;; ...
- Java利用Math.random()方法随机生成A-Z的字符
package reverse; import java.text.DecimalFormat; public class Reverse { public static void main(Stri ...
- Math.random引发的骗术,绝对是用随机数骗前端妹纸的最佳方法
我觉得今天我运气特好,今天我们来赌一赌,我们来搞个随机数,Math.floor(Math.random() * 10),如果这个数等于0到7,这个月的饭,我全请了,如果是8或9,你就请一个礼拜成不?于 ...
随机推荐
- java高级开发
(转载)博客原文链接:https://www.cnblogs.com/java1024/p/8594784.html 一.面试题基础总结 1. JVM结构原理.GC工作机制详解 答:具体参照:JVM结 ...
- Windows使用telnet验证服务端口是否通
使用telnet指令时,Windows需要开启Telnet服务. telnet不通的情况: a.端口对应的服务没启动,或者启动了服务端口不是对应的测试端口. b.端口受限不能访问. 以下内容转自:ht ...
- MySQL 正则(Regular Expression) 邮箱(Email)
MySQL 正则表达式 | 菜鸟教程https://www.runoob.com/mysql/mysql-regexp.html (1条消息)常用正则表达式—邮箱(Email) - Samuel - ...
- Redis For Windows安装及密码
启动要先开启一个控制台作为服务端,启动服务,然后在重新打开一个控制台,连接服务进行操作. redis-server.exe redis.conf 重新打开一个控制台,刚开始连接服务,因为初始没有密码, ...
- PHP 对象继承
对象继承 继承已为大家所熟知的一个程序设计特性,PHP 的对象模型也使用了继承.继承将会影响到类与类,对象与对象之间的关系. 比如,当扩展一个类,子类就会继承父类所有公有的和受保护的方法.除非子类覆盖 ...
- 【转载】 导入GoogleClusterData到MySQL
原文地址: https://www.cnblogs.com/instant7/p/4159022.html ---------------------------------------------- ...
- @ServeletComponentScan和@ComponentScan的区别
一.SpringBoot中使用Servlet在SpringBootApplication上使用@ServletComponentScan注解后,Servlet.Filter.Listener可以直接通 ...
- QVector init error
QMetaType::registerType: Binary compatibility break -- Size mismatch for type 'PtsData' [1025]. Prev ...
- Java Sound Capture from Microphone working code
转载自:http://ganeshtiwaridotcomdotnp.blogspot.com/2011/12/java-sound-capture-from-microphone.html Soun ...
- Python文件的读取写入操作
一.打开文件.关闭文件操作 想要读取文件或是写入文件,第一步便是打开文件,最后一步便是关闭文件.这里介绍两种打开(关闭)文件的方式: 1.open()方法 f=open(file_name[,acce ...