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

184
Visualizações
Encryption Using Javascript and Python doesn't have the same output

Im currently working with encryption for both Python and Javascript. I have currently working with RSA combined with base64 where I have this code for both python and javascript:

Javascript:

const NodeRSA = require('node-rsa');

const key = new NodeRSA("-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCzjsLuAJ18f71jg+ZG/wef3FuFTFK2ZvqBPjM7EwVj1FcLkzfixx6D6u59leFgW4SptOIgBtm9OGW1cCmxYLx1nHkugvoAL9g/vnIz6ejVTcoVYPJwkaGum3qXCPW6Km0canc7/DJtM//Zum40AZls/ZFjJ2YJrEOfevIU77urUwIDAQAB-----END PUBLIC KEY-----");

var x = {store_id: 1, url_key: 'hello_world.html', category_id: ''}

const data = key.encrypt(JSON.stringify(x), 'base64')
console.log(data)

and Python:

import base64
import json

import rsa

pub = rsa.PublicKey.load_pkcs1_openssl_pem('''-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCzjsLuAJ18f71jg+ZG/wef3FuFTFK2ZvqBPjM7EwVj1FcLkzfixx6D6u59leFgW4SptOIgBtm9OGW1cCmxYLx1nHkugvoAL9g/vnIz6ejVTcoVYPJwkaGum3qXCPW6Km0canc7/DJtM//Zum40AZls/ZFjJ2YJrEOfevIU77urUwIDAQAB\n-----END PUBLIC KEY-----''')
payload = json.dumps({'store_id': 1, 'url_key': 'hello_world.html', 'category_id': ''},
                     separators=(',', ':')).encode('utf-8')

bs64_encoded = base64.b64encode(rsa.encrypt(payload, pub))
print(bs64_encoded.decode('utf-8'))

Output for Javascript:

mBXCV95Dpc0sg8gigQWv1WdJNkLU9rlVQTcsFy6ell0PTsDfPh8EAVqFZBL6zM3i3S7P0Z2rSRCJQ6xGQag4yeupZ8yJIttyLk1HNIowhB/nPWqUxAPn59cL2uqP5hMBXSPLYet67DWEzwNkmHA4W2pZc/ysKrTLqUQBYGRYQQ97z3n8kGaGQLgg5afKXHPFne6qEjhiupH6cRKzwj7jwy0fEosBleyDaXWOaNtrK2drGpyR3OFVVq2QtlyXLt1kbYAV01eRSZatgRH0pNXQKEkwqSDmoEz4txDEaP/KU4nwroN/r40cOHYd1/pW2aMqjY0yTM3fm4rWM/nRQAYX5w==

Output for Python:

OPpU/VMEq7238VQamObgNX8r7pbUnvvNQ/5ie42EpWF3yXT4vNUFxNVaqvMdlNYft6FvVTs5xoAuuhg2JKRk6ar0EvIQL2ZxasIvAIpLhDazJijU5+JQ7u9nEY03QrXbrfHro3620g26LtOw5hAjjUy7pKLKO0hNO+bdobUZrio=

and as you can see there is a difference and the output of Javascript is the correct output that im looking for but not python (When using the output, it thorws an invalid data while Javascript response with 200 (correct data)).

My question is that why does it has any difference between Javascript and python when it comes to encryption and how can I make the output of Python to be correct?

about 4 years ago · Juan Pablo Isaza
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