Use window.crypto in nodejs code

前端 未结 2 1033
难免孤独
难免孤独 2021-02-19 02:21

I am trying to use the window.crypto.getRandomValues method in a nodejs script. From my understanding there is no window element when I run a simple co

相关标签:
2条回答
  • 2021-02-19 03:15

    You can use the built-in crypto module instead. It provides both a crypto.randomBytes() as well as a crypto.pseudoRandomBytes().

    However it should be noted that these methods give you a Buffer object, you cannot pass in a Uint32Array or similar, so the API is a bit different.

    0 讨论(0)
  • 2021-02-19 03:21

    You can use this module which is the same as the window element: get-random-values

    Install it:

    npm install get-random-values --save
    

    Use it:

    var getRandomValues = require('get-random-values');
    
    var array = new Uint32Array(10);
    getRandomValues(array);
    
    0 讨论(0)
提交回复
热议问题