Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda