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

132
Visualizações
Equivalent of nodejs crypto crypto.createSign in Python

I want to get the same result with Python.

function generateSignature(baseString, privateKey, clientSecret) {
  var signWith = {
    key: (privateKey)
  }; // Provides private key

  if (!_.isUndefined(clientSecret) && !_.isEmpty(clientSecret)) _.set(signWith, "passphrase", clientSecret);

  // Load pem file containing the x509 cert & private key & sign the base string with it to produce the Digital Signature
  var signature = crypto.createSign('RSA-SHA256')
    .update(baseString)
    .sign(signWith, 'base64');

  return signature;
}

What I did in Python

    import base64
    from cryptography.hazmat.primitives.asymmetric import dsa, rsa
    from cryptography.hazmat.primitives.serialization import load_pem_private_key
    private_key = load_pem_private_key(
        str.encode(str_private_key),
        password=None)

    plain_text = b'abc'
    signature = private_key.sign(
        data=plain_text,
        padding=padding.PSS(
            mgf=padding.MGF1(hashes.SHA256()),
            salt_length=padding.PSS.MAX_LENGTH
        ),
        algorithm=hashes.SHA256()

    )

    print(base64.b64encode(signature))

I do not know where to start. crypto documentation is quite short. How the passphrase is used in crypto ?

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

0

The NodeJS code uses PKCS#1 v1.5 padding, the Python code OAEPadding. To apply PKCS#1 v1.5 in Python as well, change the padding as follows:

signature = private_key.sign(
    data=plain_text,
    padding=PKCS1v15(),         # Fix: Apply PKCS#1 v1.5
    algorithm=hashes.SHA256()
)
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