我有这个 Java 代码/Groovy 代码:
import org.apache.ws.security.util.Base64;
import java.security.SecureRandom;
def generate_nonce() {
def random = SecureRandom.getInstance("SHA1PRNG");
random.setSeed(System.currentTimeMillis());
def nonceValue = new byte[16];
random.nextBytes(nonceValue);
return Base64.encode(nonceValue);
}
我正在尝试在 Javascript-NodeJs 中创建等效项。实用程序/SHA1PRNG 是这个模块https://github.com/bombworm/SHA1PRNG。有人可以帮忙吗?
const crypto = require('crypto');
const secureRandom = require('./utilities/SHA1PRNG');
function generate_nonce () {
let nonce = secureRandom(Date.now().toString());
let nonceValue = crypto.randomBytes(16);
// incomplete part, below does not work
// return nonceValue.update(secureRandom).toString('base64');
};