Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!