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,你就请一个礼拜成不?于 ...
随机推荐
- OpenGL ES: (5) OpenGL的基本概念、OpenGL ES 在屏幕产生图片的过程、OpenGL管线(pipeline)
一. OpenGL的基本概念 OpenGL 的结构可以从逻辑上划分为下面 3 个部分: 图元(Primitives) 缓冲区(Buffers) 光栅化(Rasterize) 图元(Primitives ...
- APP:目录
ylbtech-APP:目录 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 6.返回顶部 7.返回顶部 8.返回顶部 9.返回顶部 ...
- Flutter BottomNavigationBar 组件
BottomNavigationBar 是底部导航条,可以让我们定义底部 Tab 切换,bottomNavigationBar是 Scaffold 组件的参数. BottomNavigationBar ...
- Fiddler抓包工具版面认识(一)
Fiddler是一个蛮好用的抓包工具,可以将网络传输发送与接受的数据包进行截获.重发.编辑.转存等操作.也可以用来检测网络安全.反正好处多多,举之不尽呀!当年学习的时候也蛮费劲,一些蛮实用隐藏的小功能 ...
- 013-docker-安装-Centos7
1.搜索镜像 docker search centos 2.拉取合适镜像 选择合适tag:https://hub.docker.com/,下载合适版本 docker pull centos:6.6 d ...
- python哲学
import this The Zen of Python, by Tim Peters # python的设计哲学, 作者:Tim Peters Beautiful is better than u ...
- 三种构建方式:Makefile、scons、scons cmake+ninja
三种构建方式: Makefile scons cmake+ninja https://ninja-build.org
- LeetCode_283. Move Zeroes
283. Move Zeroes Easy Given an array nums, write a function to move all 0's to the end of it while m ...
- 简单明了的注解,读取CLASS中的注解
/***********注解声明***************/ /** * 水果名称注解 * @author peida * */ @Target(ElementType.FIELD) @Reten ...
- react 生命周期图解
参考地址:https://www.cnblogs.com/gdsblog/p/7348375.html