Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

269
Visualizações
How can we generate Random Salt of 32 bytes in Rhino JS

I am trying to generate a random salt of 32 bytes size. But my JS engine Rhino 1.7.13 doesn't support SecureRandom class.

Below is the code snippet of the same.

function getSalt() {
    var random = new SecureRandom();
    var salt1 = new Array(32);
    random.nextBytes(salt1);
    return salt1;
}

Error logged as below.

java.util.concurrent.ExecutionException: javax.script.ScriptException: ReferenceError: "SecureRandom" is not defined.

Also, rhino js engine does not allow any import or load of external library. Is there a way we can generate secure random salts in Rhino?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

For SecureRandom use the fully qualified name java.security.SecureRandom. And the byte array has to be a Java byte array, otherwise you'll get an error:

Cannot convert org.mozilla.javascript.NativeArray@6b419da to byte[]

I found this answer from Tomasz Gawel, which shows how to create a Java byte array in Rhino.

With the above-mentioned modifications, the complete script is:

function getSalt() {
    var random = new java.security.SecureRandom();
    var salt1 = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 32)
    random.nextBytes(salt1);
    return salt1;
}

saltB64 = java.lang.String(java.util.Base64.getEncoder().encode(getSalt()))
print(saltB64)
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda