473,396 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Javascript - Python RSA encryption interoperability

Hello,

I'm trying to encrypt a string with RSA. But it needs to be compitable
with Dave's JavaScript RSA implementation*. I'm already read and tried
lots of different things about RSA and RSA in Python. But could not
produce the same result with the javascript library.

My experiments could be seen at: http://dpaste.com/hold/60741/

* JavaScript RSA Library: http://www.ohdave.com/rsa/

Python libraries which I tried;
* PyCrtypo: http://www.amk.ca/python/code/crypto.html
* rsa library from http://www.stuvel.eu/rsa

How could I create the same results with the JS library in Python.
Any help would be appreciated

Evren,
Jul 4 '08 #1
3 3477
Evren Esat Ozkan napisał(a):
Hello,

I'm trying to encrypt a string with RSA. But it needs to be compitable
with Dave's JavaScript RSA implementation*. I'm already read and tried
lots of different things about RSA and RSA in Python. But could not
produce the same result with the javascript library.

My experiments could be seen at: http://dpaste.com/hold/60741/

* JavaScript RSA Library: http://www.ohdave.com/rsa/

Python libraries which I tried;
* PyCrtypo: http://www.amk.ca/python/code/crypto.html
* rsa library from http://www.stuvel.eu/rsa

How could I create the same results with the JS library in Python.
Any help would be appreciated

Evren,
It seems that this Javascript is doing weird things to its input,
namely processing it in reverse. Try encrypting ciphertext[::-1]
instead of just ciphertext.

public_modulus_hex = '9F2E..snip..4BC7'
public_exponent_hex = '10001'
public_modulus = int(public_modulus_hex, 16)
public_exponent = int(public_exponent_hex, 16)

def encrypt(plaintext_text):
# Beware, plaintext must be short enough to fit in a single block!
plaintext = int(plaintext_text.encode('hex'), 16)
ciphertext = pow(plaintext, public_exponent, public_modulus)
return '%X' % ciphertext # return hex representation

print encrypt('12345')
print encrypt('12345'[::-1]) # Will return the value compatible with
JS output

Regards,
Marek
Jul 4 '08 #2
Hi,

Thank you very much. Your code is worked like a charm and saved my
honeymoon :)

Thanks again,
Evren
On Jul 4, 6:19*pm, marek.ro...@wp.pl wrote:
Evren Esat Ozkan napisał(a):


Hello,
I'm trying to encrypt a string with RSA. But it needs to be compitable
with Dave's JavaScript RSA implementation*. I'm already read and tried
lots of different things about RSA and RSA in Python. But could not
produce the same result with the javascript library.
My experiments could be seen at:http://dpaste.com/hold/60741/
* JavaScript RSA Library:http://www.ohdave.com/rsa/
Python libraries which I tried;
* PyCrtypo:http://www.amk.ca/python/code/crypto.html
* rsa library fromhttp://www.stuvel.eu/rsa
How could I create the same results with the JS library in Python.
Any help would be appreciated
Evren,

It seems that this Javascript is doing weird things to its input,
namely processing it in reverse. Try encrypting ciphertext[::-1]
instead of just ciphertext.

public_modulus_hex = '9F2E..snip..4BC7'
public_exponent_hex = '10001'
public_modulus = int(public_modulus_hex, 16)
public_exponent = int(public_exponent_hex, 16)

def encrypt(plaintext_text):
* * * * # Beware, plaintext must be short enough to fit in a single block!
* * * * plaintext = int(plaintext_text.encode('hex'), 16)
* * * * ciphertext = pow(plaintext, public_exponent, public_modulus)
* * * * return '%X' % ciphertext # return hex representation

print encrypt('12345')
print encrypt('12345'[::-1]) # Will return the value compatible with
JS output

Regards,
Marek
Jul 17 '08 #3
Evren Esat Ozkan <sl****@gmail.comwrites:
I'm trying to encrypt a string with RSA. But it needs to be compitable
with Dave's JavaScript RSA implementation*.
What exactly are you trying to do? That Javascript implementation
looks like bad news. If you're trying to secure a web page, use SSL,
don't mess around with trying to encrypt it with Javascript.
Jul 17 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Will | last post by:
Pardon two post in a row to the newsgroup but I want to try and expedite this, if you guys don't mind helping out... I running Windows XP Pro and wanted to download Python and any additional...
4
by: Daniel Orner | last post by:
Hello, I'm working on a project that consists of a Java application on the desktop, and a server with Python CGI code. I'm trying to find an encryption algorithm, which would let me send...
2
by: Michael Foord | last post by:
Please pardon my ignorance on this one - but I'm not certain how the sign bt is treated in python bitwise operators. I've trying to convert a javascript DES encryption routine into python. ...
34
by: Blake T. Garretson | last post by:
I want to save some sensitive data (passwords, PIN numbers, etc.) to disk in a secure manner in one of my programs. What is the easiest/best way to accomplish strong file encryption in Python? ...
53
by: john67 | last post by:
The company I work for is about to embark on developing a commercial application that will cost us tens-of-millions to develop. When all is said and done it will have thousands of business...
5
by: Michael Sperlle | last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems to need changes to the kernel before it can be installed, and I have no intention of going through whatever hell that would...
21
by: Raj | last post by:
Hi, We just executed a project with Python using TG. The feedback was to use more python like programming rather than C style code executed in Python. The feedback is from a Python purist and...
4
by: Berco Beute | last post by:
I wonder what it would take to implement Python in JavaScript so it can run on those fancy new JavaScript VM's such as Chrome's V8 or Firefox' tracemonkey. Much the same as Python implementations...
0
by: Luke Kenneth Casson Leighton | last post by:
On Sep 3, 10:02 pm, bearophileH...@lycos.com wrote: 1200 lines of code for the compiler, and about... 800 for a basic suite of builtin types (Dict, List, set, string). ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.