Skip to main content

Python RSA module compatible with jsbn.js

Project description

pyjsbn-rsa

Python RSA module compatible with jsbn.js.

Installation

pyjsbn-rsa is available via PyPI

pip install pyjsbn-rsa

via setup.py

python setup.py install

Basic Use

You can test module with jsbn's RSA Encryption Demo

>>from jsbn import RSAKey
>>rsa = RSAKey()
>>rsa.generate(1024,"10001")
>>hex(rsa.n)
0xdc36096d038a56e84c6290f33db80dce54413e89dc15f0490dde8f1f58e69d957eed66c9537918b8fefd6a3fc9fc7b2551ac595bc77c2b98bcfa13f7deb17e94890ae4f28016f0d3e09450054263ae71f81539b09ea42b854492691e94de5671835b4ce91b9756b651ec4bbebe63eec8b7274e157b8de07457f2d3563119ac53L

Paste rsa.n to demo's Modulus (hex) and press encryt. (without "0x" and "L") And, get Ciphertext (hex) value

>>ctext="ceffa610eb7ec7fcbda60b2fdecf6d7cc65b7304ecb6e327056f15d763f1d079d376dbc801861a0ccb2731f836e75de0bb22350b3cd0d18eed216619b9e64a59dc06e15ef2531f0d3c176882444c5919dd751e9bcaefadff372d847b001a298751ebc69f9d310d92c217ab2fa433e3b3c7e8edf4744849560a317ef7f4ee7266"
>>rsa.decrypt(ctext)
'Hello World!'

Methods

You can use main methods of rsa.js and rsa2.js

setPublic

Set the public key fields N and e from hex strings.

>>rsa.setPublic(n,e)

setPrivate

Set the private key fields N, e, and d from hex strings.

>>rsa.setPrivate(n,e,d)

setPrivateEx

Set the private key fields N, e, d and CRT params from hex strings.

>>rsa.setPrivateEx(n,e,d,p,q,dp,dq,c)

encrypt

Return the PKCS#1 RSA encryption of "text" as an even-length hex string. You should do setPublic, setPrivate, setPrivateEx or generate first. text must be unicode for Python 2 and str for Python 3.

>>rsa.encrypt(text)

decrypt

Return the PKCS#1 RSA decryption of "ctext". "ctext" is an even-length hex string and the output is a plain string. You should do setPrivate, setPrivateEx or generate first.

>>rsa.decrypt(ctext)

generate

Generate a new random private key B bits long, using public expt E

>>rsa.generate(b,e)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyjsbn-rsa-0.4.2.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

pyjsbn_rsa-0.4.2-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file pyjsbn-rsa-0.4.2.tar.gz.

File metadata

  • Download URL: pyjsbn-rsa-0.4.2.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

File hashes

Hashes for pyjsbn-rsa-0.4.2.tar.gz
Algorithm Hash digest
SHA256 66087e1d8864a3d710c08a2a84d8a7fa52d0119f9f6cf8216e8c5eea4132ec38
MD5 9e53b816a3e488a9fd28ed75724b8e0e
BLAKE2b-256 704ed879adc14ad4ebe015437bdd443a1ca38ee0d108f37ccd035e61ef95bcff

See more details on using hashes here.

File details

Details for the file pyjsbn_rsa-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: pyjsbn_rsa-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

File hashes

Hashes for pyjsbn_rsa-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2fbd25a8772ac220ff0d2e3b93e7e924ccb96a440412512bd2c94899d7585109
MD5 6924cdaabcac506fdf2dc22fb5e9a127
BLAKE2b-256 37e48c2176868d4e8acc1bedf8bfaf80f17f354186d8a7c9ba4ceec8eab472a7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page