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

307
Visualizações
crypto verifier.verify() always returns false - javascript

I am trying to use the cypto verifier.verify to verify an RSA signature with my public key. When I do it on openssl, the verification returns as verified OK, but when I do it in my program, verifier.verify always returns false. This is the openssl command I tested to ensure that there is no problem with my signature or public key.

openSSL> dgst -sha256 -verify pubkey.pem -signature sign.txt.sha256 sign.txt Verified OK

event is the signature that is passed in: "AIcrnumIAYQ6GegOIQzUlz9FS/uIiVlprXQyp8SFTtEEq4B/xv4flufsf35RS5Ki
ajUgAGWnmQ1gdXVNAV3Hpidip2EXTrHyfNF8MCGhueCgKPNML9fA+pW0K8RLTDUK
6V8/41fwQ+d/k6LjErenoa8sXFC3qRAg3w6xzmrtfLnHqjYW86kRVo4fCzAOeHse
a4jtJ9+EDjJfwB4vnP4eMF/QlrRvc1+U4aVB3nEtPb/l8/c5W70NWGz3JOrpENum
E7GnjwSk6bOysDQxCQ1z+AF4fv/VqmBizF4LFk+NbyYM8Z4T/cMlz0bU4VNJBlf5
k526esT9Mj4Eo93y+fW+cA=="

    const crypto = require('crypto');
    var fs = require('fs');
    var expired = false;


    const pub = '-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApnVi9xDUe6+Kimb2TniZ\nX/pBGIhy5glXpHYgGmTOeYQa45bDkdwn3ydk15M/K7xpwJsHWSM2K2cQzCO7YCu8\nrgEMHggezt69KtXt78ohNy7AwD2Vheo6uXfaR91X9bc2dZ9oR2pEWHh3MX5jXA9y\nRopDfA/xdWj8ZiZK0RPGzyGufRauhFUaf48+2emr0nwluAfl5v1fV7vm/sBxitbj\nwl7rmka6SYodhMPRnMphFbv66sN50fPcZop8kWHp+LcvXB0TIhccRvnPHkTqjc7/\nbGiGQly6cL7JkQrDbcDCuGqPc397qDHb2ABpyZKWCHpkVAwNyc5Y1uOjaSJgPwq6\n8QIDAQAB\n-----END PUBLIC KEY-----\n';

    exports.handler = (event, context, callback) => {

    // from site https://github.com/nodejs/node-v0.x-archive/issues/6938
    //data is signed string that's passed into this in an above not shown function wrapper.
        try{
        //var message = new Buffer(event);   
        var message = event //needs to be just string apparently
        var verifier = crypto.createVerify("RSA-SHA256");
        console.log("message " + message);   
        //verifier.update takes in the string that was signed.
        verifier.update(message); //was data

        //verifier.verify
        //pub is a string of public signature in PEM format
        //signature is the base64 binary encoded version of data
        //base64 tells the format so it can be verified
        //expired is a bool, for this example, hard coded above to false, you'll want to check that for real.

        //console.log('vf: ', verifier.verify(pub, message, 'base64'));


        callback(null, {
            verified: (verifier.verify(pub, message, 'base64'))
        });
        } catch (e) {
        callback("Bad Request: " + e);
        }
    };
over 4 years ago · Santiago Trujillo
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